Snipe.Net - Geeky Stuff

Fixing Comment Count Bug in Disqus on WordPress

My final post for 2009 should probably have been more climactic. If I had planned it right, the Death in the Digital Age post should have been my last for this year. Oh well.

I mentioned in a previous post that I was switching the comments system on Snipe.Net to Disqus, and although I’ve been overall quite happy with the changeover, one issue that frustrating to me is that the comment count on the site’s homepage, category pages, and individual blog post pages (single.php) was kinda fux0red.

On the homepage, it displayed “x comments and y reactions” which made the text too long for the carefully crafted masking tape strip meant to contain them. On the blog post article pages, it shows “Comments”, omitting the comment count altogether.

I found a way to fix it, and the site that contained part one of the fix is now unavailable, I figured I’d post it here in case anyone needs it:

Around line 275 of the DISQUS plugin in disqus.php (accessible via dashboard – plugins – editor), you’ll see the following:

} else if ( (is_single() || is_page() || $withcomments || is_feed()) ) {

change this line to:

} else if ( (is_page() || $withcomments || is_feed()) ) {

When I did this, I was then seeing duplicate “X Comments”, one from WordPress and one from Disqus – in other words, the page was displaying both the WordPress version and the Disqus version, but taking out the WP Comments counter in the single.php removed the code Disqus was replacing, so I ended up with no comments.

The solution for me was to add style=”display: none” to the WordPress comments part of the single.php file, so it looks like this:

<a href="#disqus_thread" style="display: none;">< ?php comments_number('0 Comments', '1 Comment', '% Comments', 'number'); ?></a>

If your comment counter is still showing “and x reactions”, there is a way to fix this too, although it kind of sucks. In your Disqus control panel, in SETTINGS in the CUSTOMIZE tab, you have to remove the template text that is in place for the Reactions section:

The reason this sucks is because by removing the template text here, it also removes the number count text from the Reactions section below the comments block on the article pages, as you can see in my comments block below. It still shows a “Reactions” header, but instead of showing “34 Reactions”, it leaves off the running tally of reactions to the post. I don’t know of a workaround for this yet, but it’s what I had to do to get the comment counter to fit on the tiny masking tape design again.

This leaves the text in the source, so the Disqus Javascript can successfully replace it with it’s own comment counter, but hides it from displaying to the user.

Hope that helps – happy new year :)

Also check out:

If you think this article kicked ass, subscribe to the RSS feed or follow me on Twitter! Share with your friends, or leave a comment below (or better still, do both!) My entire concept of self-worth is in your hands, so that makes you kind of a big deal. Srsly.

This entry was posted on Thursday, December 31st, 2009 at 9:19 pm and is filed under Web Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

View Comments to “Fixing Comment Count Bug in Disqus on WordPress”

  1. Jan 7th

    Glad you found the code to fix for your template =)

  2. Jan 8th

    Hi Giannii – I did, sort of. When I modify the code, the reaction count still shows unless I remove the template text in the Disqus admin (I added a screenshot to this post, back up in the main body of the post). By doing that, it drops the tally on the reactions in the comments box area. Is there any kind of workaround? (In other words, if I want the reaction count to be hidden in the index pages and small masking tape area that is only big enough for the comments count, I have to take it out of the template – and when I do that, the number of reactions isn't displayed below my comments anymore.)

  3. Jan 10th

    Thank you for the tip, I have this exact problem. Your solution is working fine on my test-site, so Disqus will go live on my main site in a few days (hopefully everything will go smooth).

    You have an excellent blog by the way, like it very much.

  4. Jan 11th

    Hi Eddie – so glad it helped – and thanks for the kind words! :)

  5. axecrea
    Jan 16th

  6. Jan 18th

    Thanks for sharing

  7. Jan 19th

    Superb, worked great, many thanks!

  8. Jan 25th

    Thank you!
    worked great fo me.

  9. hadleybishop
    Apr 12th

    Hi, Glad to see this post I hope,I will see your next post soon.

  10. robertdc554
    May 29th

    what a great article, thanks for publishing this. will read more from you many thanks!

  11. Aug 16th

    Thanks for the information.

  12. Aug 27th

    Hello,
    actually I cannot find the right line, I have only this one: if ( get_option(‘disqus_cc_fix’) == ’1′ || !count($query->posts) || is_single() || is_page() || is_feed() ) { return

    Can you help me solve this issue?=

Leave a Reply

Like this site? Buy me a beer!
blog comments powered by Disqus