Skip to content

Hide “0 Comments” link in WordPress when using the Disqus Plugin

“Google Fail” posts usually have absolutely nothing to do with what I normally blog about, but are attempts to fill gaps in the mighty collective internet knowledgebase. They are triggered by rare cases where Google has failed me in my search to find some piece of information, or easy instruction on how to do something, and I’ve had to solve the problem myself like in “the olden days” (with hardtack, and liberal application of cholera).

I’ve been using the excellent “Disqus” WordPress plugin for a number of websites, but have been increasingly frustrated that there didn’t appear to be an easy way to modify the shorthand comment count links that appeared in the themes (usually “0 Comments”, “1 Comment”, or “# Comments”). Traditionally in WordPress this would be done through simply modifying the comments_popup_link function in the theme. However because Disqus overwrites this link any customization to this function (like not displaying “0 Comments” at all) were ignored.

I tried adapting a little code snippit from this wordpress support forums thread:

<?php $comment_count = get_comment_count($post->ID); ?>

<?php if ($comment_count['approved'] > 0) : ?>(original comments_popup_link code here)<?php endif; ?>

(Because my Disqus synch’s comments with my WordPress installation “just in case” – basically put everything in a big IF statement so that the comments_popup_link is *only* written if at least one “approved” comment exists).

It actually worked pretty well except that it turns out that get_comment_count (and a lot of wordpress comment functionality) counts trackbacks and pingbacks towards comment totals. So even with “0 Comments”, a lot of posts had a $comment_count > 0. Yes there are customizations and plugins to deal with this – but that’s not exactly an elegant fix at that point (not that anything I do is usually ever “elegant”).

So what’s the solution?

Finally I had the head-smacking realization that if you just log into your dashboard on Disqus, select the “Settings” tab, and the “Appearance” category – voila – there is a “comment count link” section at the bottom that let’s you set custom text for “Zero Comments”, “One Comments” or “Multiple Comments”. And (facepalm) these settings are propagated to your WordPress site.

One final hurdle is that Disqus doesn’t seem to let you set the “Zero Comments” field to hide (in fact entering no value caused a pretty scary error message). But you can set that field to, the webmasters favourite hack: “&nbsp;” (a non breaking space) – which effectively hides the “0 Comments”.

See what I mean about not exactly being “elegant”? Shut up. It works.

  • http://www.facebook.com/AndyFerrisMusic Andrew David Ferris

    I’m having the same problem with my website http://www.andrewferris.com
    Can anyone help me please?

  • http://www.bradfox.com Brad Fox

    Hi Andrew, you don’t seem to be using Disqus to power your comments so none of this will be particularly applicable. If you’re looking to hide the comments counter, that will require editing your theme directly – your theme author might have a comments or support section directly (or you could ask at WordPress.org forums, just make sure to be very clear about what plugins and themes your blog is running and what you’re trying to accomplish).

  • http://cam.vc/ Cam

    Nice :) Disqus really is way ahead with it’s commenting platform. I am starting to feel as thought sites without it seem a bit behind :p Great little trick! Thanks!

  • http://www.biztechconsultancy.com/magento-development.htm Magento Development

    This was the must needed post for me. Thanks a lot for this helpful post which helps me a lot and others as well. Nice sharing.

  • http://www.facebook.com/AndyFerrisMusic Andrew David Ferris

    Thank you so much, I cracked it now!