WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
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

WPBeginner» Blog» Themes» How to Show Comments on the Homepage of Your WordPress Theme

How to Show Comments on the Homepage of Your WordPress Theme

Last updated on November 15th, 2011 by Editorial Staff
31 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
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.

31 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

30 Comments

Leave a Reply
  1. venkatesh says:
    Aug 25, 2020 at 1:15 am

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

    Reply
    • WPBeginner Support says:
      Aug 25, 2020 at 10:46 am

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

      Reply
  2. Stanislaus Okeke says:
    Dec 10, 2019 at 7:25 am

    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

    Reply
    • WPBeginner Support says:
      Dec 10, 2019 at 9:34 am

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

      Reply
  3. Zia Ahmad says:
    Mar 27, 2019 at 10:52 am

    Thanks, it worked like a charm.

    Reply
    • WPBeginner Support says:
      Mar 27, 2019 at 11:41 am

      Glad our article could help :)

      Reply
  4. sujan says:
    Jan 11, 2019 at 5:40 am

    how to upload comments in word press website

    Reply
    • WPBeginner Support says:
      Jan 11, 2019 at 1:23 pm

      If you mean you have a list of comments then you could use the plugin in our article here: https://www.wpbeginner.com/plugins/how-to-import-post-ideas-from-csv-spreadsheet-in-wordpress/

      Reply
  5. nupur says:
    Dec 6, 2017 at 5:37 am

    well done

    Reply
  6. Michelle says:
    Jan 28, 2016 at 3:15 pm

    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.

    Reply
    • Andre Daniel says:
      Mar 14, 2017 at 8:55 pm

      The functions.php file

      Reply
  7. Piet says:
    Jan 27, 2016 at 11:28 pm

    Very useful! Thanks

    Reply
  8. DebJ says:
    Jan 18, 2016 at 4:27 pm

    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?

    Reply
  9. Chris says:
    Jul 21, 2014 at 9:37 pm

    Works great! Is there a way so when clicking post comment it won’t redirect to the posts page?

    Reply
  10. Big Tom says:
    Feb 13, 2014 at 8:53 pm

    Has anyone had trouble getting this to work with Disqus?

    Reply
  11. Faiz Ahmed (KUET) says:
    Jul 6, 2013 at 12:19 pm

    That was excellent .. exactly i wanted it. Thanks thanks.

    Reply
  12. Trisha says:
    Jun 27, 2013 at 6:11 am

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

    Reply
    • crystal says:
      Aug 10, 2013 at 11:20 am

      helped me! Thanks

      Reply
    • Syed ImranAli says:
      Nov 20, 2013 at 10:44 am

      Thanks. It helped me

      Reply
    • Jenny says:
      Jul 14, 2014 at 9:56 am

      helped me thanks!

      Reply
    • Jeff says:
      Dec 24, 2014 at 10:01 pm

      thanks very much for your comments, you give me great hints about this problem. Although this post is published 3 years ago, but it still works.Thanks wpbeginner.
      By the way, it’s a good idea to add this on the functions.php of child theme through hook, so your changes won’t lost when updating your theme.

      Reply
  13. Trisha says:
    Jun 26, 2013 at 10:56 am

    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;

    Reply
  14. Jerad says:
    Apr 5, 2013 at 6:24 pm

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

    Reply
  15. John says:
    Jul 11, 2012 at 5:27 pm

    Use:

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

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

    Reply
    • Josh says:
      May 1, 2013 at 9:11 pm

      Yes!! Thanks for this additional tip, this was driving me crazy. ;)

      Reply
  16. Japh says:
    Nov 16, 2011 at 11:50 pm

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

    Reply
  17. Faizan Elahi ( BestBloggingTools) says:
    Nov 16, 2011 at 11:19 am

    Nice tip !

    Reply
  18. jauhari says:
    Nov 15, 2011 at 5:47 pm

    Thanks… let’s me try it

    Reply
  19. Da'Scott Says Ifihadarockidbussyoheadbich says:
    Nov 15, 2011 at 12:28 pm

    Just starting with wp so yes i need it thanx

    Reply
  20. Mitchell Allen says:
    Nov 15, 2011 at 11:05 am

    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

    Reply

Leave a Reply Cancel 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.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
TrustPulse
TrustPulse
Instantly get 15% more conversions with social proof. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
WP Business Reviews
WP Business Reviews Coupon
Get 15% OFF on WP Business Reviews plugin for WordPress.
Google Fonts for WordPress
Google Fonts for WordPress Coupon
Get 30% OFF on Google Fonts plugin for WordPress websites.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.