How to Add Disqus Comment Counts to Your Individual Post Pages


The Disqus commenting system does a great job integrating seamlessly with WordPress comments as well as adding a lot of additional functionality compared to the native WP comment system.

There is however a bit of tweaking you’ll need to do if you want to be able to dynamically display your comment count on individual post pages. Adding the code itself is a pretty straightforward process. The most difficult part, at least for me, was wading through and finding the right documentation which is why I’m putting this up, in hopes that it will save someone else some time.

Adding Disqus Comment Count on Individual Posts

Step 1: Add the following code to the bottom of your template directly before the </body> tag.
Important: Be sure to edit the disqus_shortname and change ‘example’ to your Disqus shortname:
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'example'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>

Once that’s added you simply have to find where the WordPress “View Comments” link is displaying on your post pages and append #disqus_thread to the href attribute at the end of your link. For example:
<a href="<?php the_permalink(); ?>#disqus_thread">View Comments</a>

That’s it! Once the page loads it will use the javascript to pull in your dynamic post count from Disqus and replace the static “View Comments” link. To see it in action simply reload this page and keep an eye on the comment count above the post.

Advertisements

3 thoughts on “How to Add Disqus Comment Counts to Your Individual Post Pages

  1. Pingback: Blog Ideas Community Members

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s