How to Prevent Disqus from overriding your WordPress Comment Count

173

Disqus, a comment platform, tends to go out and change the comments number hook for WordPress. This may end up causing your theme to show the text “View Comments” instead of the actual comment count that you want it to show. The reason why Disqus tries to replace the comment count shown by WordPress is that it will be out of sync with the actual comment count on many occasions. So by having these replacement settings, your comment counts should match what they are in Disqus however getting rid of this replacement settings will make your pages load faster. Recently, we had an opportunity to work on a client’s site that had this issue ruining the styling of their comments count box. In this article, we will show you how to prevent Disqus from overriding your WordPress Comment Count in themes.

After doing a lot of search over the internet (including the GetSatisfaction forms for Disqus), we saw that most places on the web suggested that we go in the Advanced Options tab and turn on this JavaScript option for comment counts which should fix the problem. You can get to the Disqus advanced options tab by going to Comments &raquo Disqus (look on the top right corner of the screen). Refer to the image below:

Disqus Advanced Options Panel

This option will output a JavaScript in your theme’s footer. So make sure that the footer.php file actually has wp_footer(); function in there. Most themes will have that in there, but unfortunately the one we were working with did not. So we had to add it in. This will solve the issue. On every page load the text “View Comments” will show up then it will be replaced in a split second with the actual comment count. However, if you notice your page load time would get slower.

After doing further research, we ended up on Themehybrid Forums where Adam Capriola suggested an alternative. First you need to open your theme’s functions.php file and paste the following codes:

  // Disqus: Prevent from replacing comment count  remove_filter('comments_number', 'dsq_comments_text');  remove_filter('get_comments_number', 'dsq_comments_number');  remove_action('loop_end', 'dsq_loop_end');  

Your comment count might be off if you do this. So you should go in your Discussions setting and disable Trackbacks. Also check the boxes that says commenters must be registered and they must have a previously approved comment.

That was quite a bit of hassle to make sure that we get the right comment count number in our WordPress themes.