How to Show Comments on the Homepage of Your WordPress Theme

117

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.