Fix: WordPress 3.1 and Disqus Plugin Error When Returning Comments Count

If you use the popular 3rd-party commenting system Disqus in your WordPress-powered website, you may have noticed that some errors appeared in your Posts lists after upgrading to WordPress 3.1.  The specific error you see would be something like:

Warning: number_format() expects parameter 1 to be double, string given in /wp-includes/functions.php on line 155

I’ve had problems with Disqus messing with WordPress comment counts in the past, and since those minor problems were never properly resolved, they caused more severe problems when WordPress updated their Posts view in version 3.1.

Essentially, Disqus takes the WordPress comment count and reformats it internally to wrap it in an identifying span that follows the format:


{number of comments}

Disqus effectively usurps WordPress’s comment count (which isn’t a big deal by itself), but the added HTML around the comment count is what breaks WordPress 3.1.

Why It Breaks

In the WordPress core file /wp-admin/includes/class-wp-list-table.php, WordPress makes a call to the get_comments_number() function and passes it to its internal function number_format_i18n().  Since Disqus has replaced the normal value returned from get_comments_number() with its own value wrapped in HTML, this breaks WordPress’s number_format_i18n function which expects the value to be a double instead of a string.

After quite a bit of troubleshooting, I figured out a way to fix this by making a small change to the Disqus plugin.

How to Fix It

Note: This method involves editing PHP files for WordPress plugins on your web server. If you do not feel comfortable following this guide, please seek assistance. And above all – make a backup!

Step 1: Edit the file /wp-content/plugins/disqus-comment-system/disqus.php

Step 2: Locate the following code at line 692:


function dsq_comments_number($count) {
 global $post;

 if ( dsq_can_replace() ) {
 return ''.$count.'';
 } else {
 return $count;
 }
}

Replace it with:


function dsq_comments_number($count) {
global $post;

return $count;
}

Step 4 (optional – this will fix comment counts in the front-end of your blog if using the comments_number() function in your theme): Locate the following code at line 697:


function dsq_comments_text($comment_text) {
global $post;

if ( dsq_can_replace() ) {
return 'View Comments';
} else {
return $comment_text;
}
}

Replace it with:


function dsq_comments_text($comment_text) {
global $post;
$number_of_comments = get_comments_number();
return $number_of_comments;
}

Finally, to display the comment count in your WordPress theme, use the following code wherever you want to display “X Comments”:




This should fix the comments count in your WordPress Posts view, and make comments appear correctly on your blog if you use the comments_number() function in your theme.

  • Easylancer

    Great fix is quick timing, I just upgraded today and faced this exact problem althought I couldn’t find where the problem was coming from until you pointed it out. Here is a fix which is more backward compatible incase the user decides to roll back to older version of wordpress without remembering to restore the changes.

    https://gist.github.com/842839

    • http://eraldmariano.com erald mariano

      i couldn’t agree more. i was totally lost and don’t know where to start.
      thanks for digging, Evans!

  • http://www.bayphillips.com Bay Phillips

    Thanks for this! I had gone in and edited the WP core file; however, it’s definitely not the correct way to go about these things. I hope Disqus updates their plugin ASAP to fix the issue.

  • http://www.scanman.com.au/ ground penetrating radar

    I hope Disqus updates their plugin ASAP to fix the issue.

  • http://aPublishedHeart.com Rishi Talreja

    Incredible. Works! Thank you :)

  • http://dspickett.co.uk DSPICKETT

    Awesome thanks for your help! :) Problem solved.

  • http://pelfusion.com PelFusion

    what i did to solve this, activated back the older version of disqus

  • http://pelfusion.com PelFusion

    what i did to solve this, activated back the older version of disqus

  • Anonymous

    This is awesome, thank you! Much love, ♥

  • http://www.scishark.com Sci Shark

    Thanks so much for this!

    I had the problem on my website after installed jetpack (disqus was already installed and working fine)

  • http://lars-mueller.mobi Lars

    great Thanks for this fix

  • Kevin

    Awesome! Thanks for the work around. Works great!

  • Kevin

    Awesome! Thanks for the work around. Works great!

  • http://thetylerhayes.com Tyler Hayes

    This is great stuff. Thanks for doing this, we’ll be sure to incorporate the fix in our next plugin release.

  • Anonymous

    Thanks a lot!

  • Cal

    I wish a came upon your post earlier, thank you very much!

  • Cal

    I wish a came upon your post earlier, thank you very much!

  • http://www.facebook.com/iadyz Florescu Adrian

    Thank you!

  • Anonymous

    Omg thank y!

  • http://seogeeker.com Seogeeker

    Thanks for the hack!

  • http://www.octaneandelectrons.com Evan Grist

    Worked great, thanks for this.

  • http://www.techhamlet.com Pubudu@TechHamlet

    Thanks a lot my friend for the post! I saw this error in my php error log. Thats how i noticed it. 😀 Now its fixed.. Thanks again 😀

  • http://www.nothinginwinnipeg.com Melissa Martin

    Oh my gosh, thank you so much.

    Quick question: now I have comment counts (yay!), but the comment link text is gone: where it used to say “X comments” in nice, medium-sized theme-coloured letters, it now shows an extremely tiny number of comments next to my theme’s small icon. How can I make this better?

    • http://www.techerator.com Evan Wondrasek

      Hey Melissa,

      Glad it helped! Using the following code in your WordPress theme should restore the “X comments” functionality:

      If you need any help using this or styling the text to match your theme, send me an email at evan at techerator dot com and I should be able to give you a hand.

      • http://www.techerator.com Evan Wondrasek

        Wow, Disqus really had its way with the code I posted in the comments. I’ll try to email you.

      • http://www.invertedworld.co.uk Nick Bramhall

        Hi Evan. Thanks for your fix in the main blog post. I too now have the problem with the “X comments” functionality as Melissa experienced. Would you mind also e-mailing me the correctly formatted code for this fix please? I can’t seem to quite get it to work properly based on what you posted? Many thanks.

        • http://www.techerator.com Evan Wondrasek

          Hey Nick, I sent you an email. I’ll update this article with that information as well for future reference.

          • http://www.teologicafet.tk Andreas Engström

            Hi, I used your fix and it worked great but as some others noted the X comments function went away somehere, probably to Hawai. If you have time to respond to this issue it would be great. But I understand if you are bussy with other things. At least I have the number of comments now. 😉 Thanks alot.

          • http://www.techerator.com Evan Wondrasek

            Hi Andreas:

            Try using this code to display your comments:

          • http://www.teologicafet.tk Andreas Engström

            I have not tried it yet, but I do suspect it will work. 

  • Pingback: Blogkeeping Note: Comments » nothing in winnipeg()

  • http://www.lukeaddison.com 1uk3

    I’ve only just noticed that I had this issue across my WordPress blogs.

    Thanks for the fix – very quick and easy but would have taken me an age to figure out on my own.

  • http://twitter.com/spinmind01 Spinmind

    Really tanks!!

  • sam

    I think you can also simply comment out Disqus’s ‘get_comments_number’ filter, e.g.,

    // add_filter(‘get_comments_number’, ‘dsq_comments_number’);around line 1125 of disqus-comment-system/disqus.php, or useremove_filter(‘get_comments_number’, ‘dsq_comments_number’);

    elsewhere, maybe?

    Thanks for saving me time debugging this! :)

  • Pingback: Fix: Disqus for WordPress showing “View Comments” instead of comment count [Updated] | L’histoire de sa vie()

  • http://www.buzzparas.com buzzparas

    after hurdling with the problem for hours,i re-installed the plugin and tried again and it worked perfectly. anyway thanx for nice share.

  • michal rock

    I think for understanding of this every blogger should need to learn some basics of HTML so he can easily edit the problem in blogs without anyone’s help. Disqus is really become more and more popular comment system in today’s time.

    psd to html

  • Anonymous

    It is one of the best way to fix it but if you will move it into the psd code it will more helpful to you for making a high quality design and you can make it from c sharp also but the way of psd is easy.

  • http://n3u.com n3u

    Thanks!

  • http://filsupport.com/web-design-outsource/ Web Design Outsource

    Thanks for sharing this one. This is very helpful.

  • http://www.superspeedlearning.com/forkids/mental-artithmetic/ Mental Arithmetic

    You should expect downtime and errors especially when Disqus would release a new version. It’s just sad that some people say Disqus is selling users’ data to third party. I do hope they don’t do that. 

  • http://www.gowebbaby.com WordPress Designer

    Nice share. It is really very helpful and only few people can help upto this level. Thanks champ….

  • Anonymous

    NOTHING 

  • http://www.gowebbaby.com Web Designer

    Nice, thanks for your tips to resolved this problem….

  • http://patentsbase.com/items/US-5761148-A-sub-word-line-driver-circuit-for-memory-blocks-of-a-semiconductor-memory-device Sub-word line driver circuit

    Thanks for this! I had gone in and edited the WP core file; however, it’s definitely not the correct way to go about these things. I hope Disqus updates their plugin ASAP to fix the issue.

  • http://www.buy-premium-themes.com/ wordpress themes

    WordPress.com is a WordPress backup and management, so you do not have to worry about backing up your article. Hundreds of servers hosted in your blog, so you never have to worry about it down.

     

  • http://www.buy-premium-themes.com/ wordpress themes

    WordPress.com is a WordPress backup and management, so you do not have to worry about backing up your article. Hundreds of servers hosted in your blog, so you never have to worry about it down.

     

  • http://www.mantrais.com/android-application-development.php Android app development

    many plugins for wordpress which i always use for my each blog.and Disqus plugin is one of them.

  • http://www.smsblaze.com/ Hindi Sms

    I adore your wordpress design, where did you obtain it through?

  • http://www.yuiasp.net/2012/01/05/website-and-mobile-apps-for-flatshare-accommodation/ mobile apps

    The spectrum of this industry is wide and so taking into consideration the demand and necessity of your users is very important. When you are developing your own app for the first time, make sure to hire a programmer that will help you reach your customers regardless of their location.

  • http://www.coolcreation.co.uk/ Website design

    To stand out in the crowd and achieve your online business goals make sure you give your web design serious consideration. Invite your designer to be creative in their implementation and design!

  • Anonymous

     Thanks for post. I dun know from where to start. thanks for helping

  • Anonymous
  • http://tobeinformed.com/about-david-snape/ David

    my problem is that after uninstalling disqus my normal blog commenting system no longer works.   Any ideas on that?   (all the previous comments are in tact)   No one can make any comments now.  

  • http://tobeinformed.com/about-david-snape/ David

    my problem is that after uninstalling disqus my normal blog commenting system no longer works.   Any ideas on that?   (all the previous comments are in tact)   No one can make any comments now.  

  • http://tobeinformed.com/about-david-snape/ David

    my problem is that after uninstalling disqus my normal blog commenting system no longer works.   Any ideas on that?   (all the previous comments are in tact)   No one can make any comments now.  

  • http://tobeinformed.com/about-david-snape/ David

    my problem is that after uninstalling disqus my normal blog commenting system no longer works.   Any ideas on that?   (all the previous comments are in tact)   No one can make any comments now.  

  • http://www.businessmasteryoutsourcing.com/ blogdesigningcompanyinusa

    yeahhh… disqus is one of the best commenting tool and working great for me too.

  • http://www.integrationworksinc.com/ Small business IT support Crys

    I just upgraded today and faced this exact problem althought I couldn’t
    find where the problem was coming from until you pointed it out. Here
    is a fix which is more backward compatible incase the user decides to
    roll back to older version of wordpress without remembering to restore
    the changes. especially when Disqus would release a new version. It’s just sad that
    some people say Disqus is selling users’ data to third party. I do hope
    they don’t do that.

  • http://www.integrationworksinc.com/ Small business IT support Crys

    I just upgraded today and faced this exact problem althought I couldn’t
    find where the problem was coming from until you pointed it out. Here
    is a fix which is more backward compatible incase the user decides to
    roll back to older version of wordpress without remembering to restore
    the changes.

  • http://www.integrationworksinc.com/ Small business IT support Crys

    I just upgraded today and faced this exact problem althought I couldn’t
    find where the problem was coming from until you pointed it out. Here
    is a fix which is more backward compatible incase the user decides to
    roll back to older version of wordpress without remembering to restore
    the changes.

  • http://www.vipinramdas.com/ Vipin Ramdas

    Dude. You are too good. Thanks you fixed a painful issue for me. Cheers!

  • http://www.tapchidanong.org/categories/Hap-dan/Thoi-trang-nam/ thanghn92

    Thanks for this! I had gone in and edited the WP core file; however,
    it’s definitely not the correct way to go about these things gia vang giay nam thoi trang FiFa Online 3 thoi trang nu tu vi xem boi mon ngon am thuc

  • http://ichiase24h.blogspot.com/ vantanhy

    great Thanks for this fix; tu vi 12 cung hoang dao