How to Show Comments on the Homepage of Your WordPress Theme

Would you like to display comments from your visitors on the homepage of your WordPress website?

This is a common request, but it’s not supported by WordPress by default.

In this article, we’ll show you how to display comments on the homepage of your WordPress theme using a code snippet.

How to Show Comments on the Homepage of Your WordPress Theme

Why Show Comments on Your Homepage?

Comments are the easiest way for your visitors to respond to your blog posts. Comments let them give feedback, ask questions, and offer their point of view.

When your posts are attracting a lot of comments, it’s a sign that you’re building a healthy community around your WordPress blog. You may want to give these comments greater visibility by displaying them on your homepage.

If your theme allows you to add widgets to your homepage, it’s simple enough to add comments in the sidebar or other widget area.

Another alternative would be to use a landing page builder to create a custom homepage.

But not all themes or landing page plugins come with an option to add comments to your homepage, so you may need a code solution.

We wanted to do this on one of our projects and discovered that it’s not as easy as we expected. To show comments on a single page you just call comments_template(); but this didn’t work on the homepage.

We were able to find the answer to this problem, and in this article, we’ll share it with you.

Showing Comments on the Homepage of Your WordPress Theme

In this tutorial, you’ll need to copy and paste code into your WordPress theme files. Experienced users will feel at home doing this, but it can be intimidating for beginners, and a mistake could crash your website.

If this is your first time adding code to your WordPress files, then you should check out our guide on how to copy paste code snippets in WordPress.

With that being said, the answer to our problem was to add an extra line of code. We needed to add $withcomments = “1”; before the comments_template(); line so that our comments would be shown.


You’ll need to add this code to your theme’s index.php file. It needs to go inside the WordPress Loop right before the endwhile statement.

How does this work in real life? Let’s look at a few examples.

Adding Comments to the Twenty Sixteen Homepage

Using an FTP program, you need to connect to your WordPress website and navigate to the /wp-content/themes/twentysixteen folder. For more details, refer to our beginner’s guide on using FTP with WordPress.

Once there, you need to edit the index.php file. Paste the following code just before the endwhile statement.

$withcomments = "1";
comments_template(); // Get wp-comments.php template

 
Index.php of the Twenty Sixteen Theme

After you save the index.php file, visit your WordPress site to see the comments displayed on the homepage.

Adding Comments to the Twenty Twenty-One Homepage

Using an FTP program, you need to connect to your WordPress website and navigate to the /wp-content/themes/twentytwentyone folder. For more details, refer to our beginner’s guide on using FTP with WordPress.

Once there, you need to edit the index.php file. With this theme there isn’t an endwhile statement, so you need to add the code before the else statement.

$withcomments = "1";
comments_template(); // Get wp-comments.php template

 
Index.php of the Twenty Twentyone Theme

After you save the index.php file, visit your WordPress site to see the comments displayed on the homepage.

Adding Comments to a Child Theme

Instead of modifying files inside a theme, you might want to create a child theme and add the code snippet there instead.

This is safer because you won’t risk breaking the parent theme, and you won’t lose your changes whenever you update the parent theme.

If you’re using a child theme and you still don’t see comments on the homepage after adding the code snippet, then you may need to add an extra line of code.

You should copy and paste this code into your index.php file instead.

global $withcomments;
$withcomments = 1;
comments_template(); // Get wp-comments.php template

We hope this tutorial helped you learn how to add comments to your WordPress theme’s homepage.

You may also want to learn how to create a free business email address, or check out our list of must have plugins to grow your site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.