Beginner's Guide for WordPress / Start your WordPress Blog in minutes

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.

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

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

32 CommentsLeave a Reply

  1. working fine, but here shows 100s of comments how can i disable comments or else remove comments in code

    • You would remove the code if you no longer want to show the comments on your homepage

      Admin

  2. Hy,
    Please where exactly am I adding the code? is it on my index.php? or front-page.php or where else?

    I’m not good at coding but I can locate the files please

    • If your theme has a front-page.php you would add it to that file for your static home page

      Admin

  3. I’m sorry if I sound dumb, but I’m not a PHP coder. Can someone please tell me which file I need to edit in order to place this text?

    Thank you very much.

  4. I’m not sure exactly where to add this code. I have the comment box code at the end of my post, but where do I put this? Before or after?

  5. Thanks for the great tip (and generally fantastic resource), it set me in the right direction when I needed to create a modification for a child theme (using Genesis as the parent theme) I needed to use the following to get the comments to display:


    global $withcomments;
    $withcomments = 1;
    comments_template( ' ', true );

    I hope this helps someone else spend less time on this problem than I did :)

  6. Recently, when I was trying to solve this problem in a child theme I needed to add this line above the two shown above in order to get it work:
    global $withcomments;

  7. Use:

    comments_template(“/comments.php”, true);

    otherwise it just repeats the first posts comments for every post.

  8. Great tip, thanks for posting about it too. I’ve noticed questions about this in the WordPress Support forums a few times with no answer given, so this will no doubt help quite a few people :)

  9. Cool tip. At long last, I’m beginning to dig a little deeper into the WordPress code. I’ve subscribed to your weekly updates! dragonblogger mentioned your blog today and then I saw this tweet in my Gmail (I use @Rapportive)

    Cheers,

    Mitch

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.