Fix WordPress comment count error caused by Disqus plugin

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
May 28, 2011

Disqus for WordPress is a great plugin for those who want to integrate a better way of adding comments to their blogs. With Disqus, you can allow your visitors to easily post comments through their Facebook or Twitter accounts. Disqus perfectly syncs with WordPress comment system and the comment on your database is also synced with Disqus’ server. But with the latest version of WordPress i.e. WordPress 3.1, Disqus has some issues showing the comment counts for the post. Here is how you can fix comment count error in WordPress 3.1 when Disqus plugin is used.

After upgrading to WordPress 3.1, you would encounter a strange error in the post list area instead of the comment count. This would happen only if you have Disqus plugin for WordPress installed. The error looks something like this:

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

Disqus comment system

This error occurs because Disqus’ comment count system uses its own value for counting comments that breaks WordPress’s default function number_format_il8n(). This function expects the comment number value to be a double instead of a string. So, we’ll have to edit a file on Disqus plugin folder.

Open the file /wp-content/plugins/disqus-comment-system/disqus.php. Now find the following line of code on your text editor.

[code]function dsq_comments_number($count)[/code]

Your code will look something like this:

[code]
function dsq_comments_number($count) {
global $post;

if ( dsq_can_replace() ) {
return ‘<span class="dsq-postid" rel="’.htmlspecialchars(dsq_identifier_for_post($post)).’">’.$count.'</span>’;
} else {
return $count;
}
}
[/code]

Simply replace the above code with the following.

[code]
function dsq_comments_number($count) {
global $post;

return $count;
}
[/code]

This will do the trick to fix error in comment count on WordPress 3.1 due to Disqus plugin.

You may also like...