Snipe.Net - Geeky Stuff
Twitter
Currently: @daleochase Did you catch this? http://bit.ly/aOUoue - these are some of the swords I was telling you about :) 34 mins ago

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

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.

Also check out:  

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.
  • Thank you!
    worked great fo me.
  • Superb, worked great, many thanks!
  • Thanks for sharing
  • 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.
  • Hi Eddie - so glad it helped - and thanks for the kind words! :)
  • Glad you found the code to fix for your template =)
  • 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.)
blog comments powered by Disqus