I must be blind but I can't find for the life of me the full instructions for getting Disqus comment count to work.

All I want displayed is just the comment count number.

I've checked the "Output JavaScript in footer" option. I have custom loops but I have no idea what I supposed to put in them to activate the comment count.

My loop.php file is:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( comments_open() ) : ?>
        <a href="<?php echo get_permalink($post->ID); ?>#disqus_thread" class="post-disqus">
           <span class="dsq-postid"></span>
           <?php echo $post->comment_count; ?>
    <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

Disqus's footer javascript code is:

<script type="text/javascript">
    // <![CDATA[
        var disqus_shortname = 'mysite';
        var disqus_domain = 'disqus.com';
        (function () {
            var nodes = document.getElementsByTagName('span');
            for (var i = 0, url; i < nodes.length; i++) {
                if (nodes[i].className.indexOf('dsq-postid') != -1) {
                    nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
                    url = nodes[i].parentNode.href.split('#', 1);
                    if (url.length == 1) url = url[0];
                    else url = url[1]
                    nodes[i].parentNode.href = url + '#disqus_thread';
            var s = document.createElement('script'); s.async = true;
            s.type = 'text/javascript';
            s.src = 'http://' + disqus_domain + '/forums/' + disqus_shortname + '/count.js';
            (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
  • I think more information would be helpful: Where did you get that code? Are you using the Disqus plugin or the universal code? What version of WP? If you are using the plugin, what version of the plugin? If you used the universal code, what is the code you used to render the Disqus comment section?
    – matt
    Mar 6, 2011 at 21:55
  • Wordpress version is the latest as is the Disqus plugin. The Javascript is Disqus's footer code. The code I'm using to render the Disqus comment is the loop code... but I'm not sure what code Disqus is looking for exactly, hence the problem.
    – EddyR
    Mar 8, 2011 at 12:39
  • Simply put... how do I get the Disqus's Wordpress plugin to display just the comment count number inside "the loop"??? All I want is example code.
    – EddyR
    Mar 8, 2011 at 12:46
  • sorry, I didn't see that you responded. I'm commenting from my phone so I don't have all the info I need in front of me. I still don't understand where you got the code. from the plugin or the universal code on their site? I don't see where too defined the disqus identifier.
    – matt
    Mar 9, 2011 at 6:40

2 Answers 2


I have the same problem with displaying number of comments in the loop.

I solve this by turn off two filters in file plugins/disqus/disqus.php at line 1124:

#add_filter('comments_number', 'dsq_comments_text');
#add_filter('get_comments_number', 'dsq_comments_number');

And I have added to my template span with disqus elements:

if ( function_exists( 'dsq_identifier_for_post' ) ) {
    global $post;
    echo  '<span class="'.$css_class.' dsq-postid" rel="'.htmlspecialchars(dsq_identifier_for_post($post)).'">';
} else {
    echo '<span class="'.$css_class.'">';
  • 1
    I came up with something similar in the end and I was going to post the solution yesterday but forgot :) Now I have alter it's predefined markup after the fact to do anything useful with it sigh
    – EddyR
    Mar 19, 2011 at 4:15


  • What's data-disqus-identifier? What's dsq_thread_id? Where do I put it? How do I call it? It's not the same code as provided by the Wordpress plugin automatically. This is my problem - they don't explain anything.
    – EddyR
    Feb 27, 2011 at 14:18
  • "You can do this by appending #disqus_thread to the end of the href attribute of your links." ... so it's something like <a href="http://example.com#disqus_thread">Your Link text</a>
    – kaiser
    Feb 27, 2011 at 15:41
  • 1
    I already did that... looking at the js code it seems to look for all <span class="dsq-postid"> then it sets attribute rel="data-disqus-identifier" to the parentnode and adds "#disqus_thread". So I assume I should be set up like <a href="mysite"><span class="dsq-postid"></span></a> but again - nothing ???
    – EddyR
    Feb 27, 2011 at 16:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.