Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Show Comments on the Homepage of Your WordPress Theme

Last updated on by
BlueHost - Recommended WordPress Hosting
How to Show Comments on the Homepage of Your WordPress Theme

Recently while working on a very secret project, we found a need to show comments on the homepage of the site. Normally, on single pages you can just call comments_template(); and it should display, but it wasn’t showing up. All we ended up getting was a blank div container. After doing a quick search online, we were able to find the answer. In this article, we will show you how to show comments on the homepage of your WordPress site.

Inside the loop right before endwhile, simply add the following code:

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

A single line $withcomments makes all the difference.

Note: this was a very simple one page site we threw up. So the theme elements were style.css, index.php, and comments.php file. We were calling a loop to display a specific page on the index.php file along with other things.

We hope that this would help some of you. Some of you may even have a better way of doing this. If you do, please share it with us in the comments.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Jerad says:

    Thank you! The $withcomments = “1″; bit was exactly what I needed.

  2. John says:

    Use:

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

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

  3. Japh says:

    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 :)

  4. Faizan Elahi ( BestBloggingTools) says:

    Nice tip !

  5. jauhari says:

    Thanks… let’s me try it

  6. Da'Scott Says Ifihadarockidbussyoheadbich says:

    Just starting with wp so yes i need it thanx

  7. Mitchell Allen says:

    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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.