Contact Me

Hide Number of Comments if None in WordPress

>> Only show Comment Numbers if there are any....

closeThis post was published 1 year 8 months 15 days ago which may make it a bit inaccurate or irrelevant today. Things change and I cant keep checking old posts for validity. I wont be held responsible for any misunderstanding. Leon - Reverb Studios

Just a quick one to tidy up your blog a little and make it a little less negative! It’s quite common to see a list of posts on a WordPress blog with meta info underneath each one displaying things like Post Time, Post Category, Author and the number of Comments the article has. For smaller blogs, there probably wont be too many comments left so you’ll see “No Comments” or “0 Comments” under a lot of the posts. I’ve always thought this looked a little sad on my own blog. Like, here I am slaving away on these excellent and informative articles and no one is reading or commenting on them!? Here’s a quick code edit to hide the “No Comments” text if there are none but show the number of comments and link to them if there are any.

Open the index.php file for your theme in a HTML editor and look for a line similar to this:

<?php comments_popup_link(’0 Comments’, ’1 Comment’, ‘% Comments ‘); ?>

Change this to:

<?php comments_popup_link(”, ’1 Comment’, ‘% Comments ‘); ?>

You’re just deleting any text that should be displayed when there are no comments so if there are none, then nothing will be shown. Geddit!?

You might need to edit this line in several other template files also such as Archive.php, Category.php, Search.php, Tag.php and anywhere else comment numbers are displayed.

Leon.

This Article has had 980 views so far.

Posted in How to Guides, Wordpress Tips on September 2nd, 2010

Follow responses to this article through the RSS 2.0 feed.
leave a Comment, or Trackback from your own site.

  • http://www.ivanwalsh.com Ivan

    Hi Leon,

    Tried this on my site above and no joy. It there any where else I need to change this line. Only found the exact line in the index.php and not in the others eg comments.php?

    Any thought, pls!

    Ivan

    • http://www.reverbstudios.ie Leon

      It should really have worked if you done it properly and are displaying all your posts on the home page, however, I don’t see any reference to comments at all in your home page articles? I only see a comment number reference on the actual article page itself so you should probably look at your “single.php” template file instead. All templates are wildly different so bare that in mind.

  • http://www.patiowindowtreatments.net patio window treatments

    Excellent! Great article, I already saved it to my
    favourite,

  • http://www.mapsofireland.ie Maps of Ireland

    good tip

Leon QuinnThanks for checking out my Site! I'm a Multimedia/Web Designer based in Leitrim, Ireland. Leon.
    • REGISTER to Automatically receive New Posts via Email as they are published. LOGIN below if you're already registered.

    • Lost Your Password?
  • Check Domains

    .
  • My Newsletter

    Sign up to receive a selection of my Latest Blog Posts each month and occasional relevant news from Reverb Studios..

    Newsletter RSS feed


    captcha

  • Subscribe?

  • Popular Keywords

  • Categories

  • Older Posts

* No responsibility will be taken for the effects, whether negative or positive, of following any of the advice on this website.

This blog is written and maintained solely by Reverb Studios Design. Contact Leon at Info@Reverbstudios.ie || or 353 76 602 5555.