Snipe.Net - Geeky Stuff

Fixing Comment Count Bug in Disqus on WordPress

closeThis post was published 2 years 1 month ago. There is a chance that some APIs or software versions discussed have changed since this article was written.

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:

[source lang='php']} else if ( (is_single() || is_page() || $withcomments || is_feed()) ) {[/source]

change this line to:

[source lang='php']} else if ( (is_page() || $withcomments || is_feed()) ) {[/source]

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:

[source lang='php']< ?php comments_number('0 Comments', '1 Comment', '% Comments', 'number'); ?>[/source]

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.
  • http://g.bonsaibeats.com Giannii

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

  • http://www.snipe.net snipe

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

  • http://lovesagame.com Eddie Corbano

    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.

  • http://www.snipe.net snipe

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

  • axecrea
  • http://www.wholesaleinc.net/ iphone clone

    Thanks for sharing

  • http://blogtechguy.com/ Joel Williams

    Superb, worked great, many thanks!

  • http://www.gtechonline.co.uk/ sweepers

    Thank you!
    worked great fo me.

  • hadleybishop

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

  • robertdc554

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

  • http://griyamobilkita.webs.com sewa mobil

    Thanks for the information.

  • http://www.liquidskydesign.org/ Claudia

    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?=

  • http://bani.deocazie.info Bani Pe Net

    i did have same issues. thanks for the info

  • http://emoneymakingonline.com Mr.Ven

    Just looking for this problem in one of my blog, thanks for your quick fix and suggestions !

  • http://www.itechmax.com/ Hammad

    Thanks alot for your help :) this worked

  • http://superdicaspfs.com.br/ Mandy

    Thanks for the tutorial