How to Display the Number of Comments in WordPress
If you want to learn how to display the total number of comments on your WordPress website this post is for you. The purpose of the comments is to help your visitors to participate as well as engage with your content. When you show the number of comments that your post has you can encourage more users to join in the conversation. But how exactly do you show how many comments your post has? This post is here to answer this question.
Display total number of comments using a plugin
The best thing about WordPress is that there is a plugin for almost anything. If you want to display the total number of comments on your WordPress website the first option you should consider is that of installing a plugin. This will save you time that would have been spent writing a code.
The best plugin for this is the Simple Blog Stats. Install and activate it. Once the plugin is installed and activated you need to go to Settings>>Simple Blog Stats page in order to configure the settings. Here you will see all the shortcodes you can use to display various stats such as the number of comments, registered users, number of posts, page count, and categories and so on.
To display the total number of comments you need to copy the [sbs_approved] shortcode. To display the number of comments, you need to create a new post or exit an existing one. On the edit screen add the shortcode block and the paste the shortcode in the new block. You will also be able to add any text that you want to be displayed before or after the shortcode.
To add the shortcode inside a paragraph block you just need to paste the shortcode where you want it to be displayed. With the paragraph block you will be able to use text styling. Publish or update your post for the changes to take effect.
Displaying total number of comments in sidebar widget
To do this you need to use the shortcode you copied from Simple Blog stats page and post it in a WordPress widget. Go to Appearance>>Widgets page and then add ‘Text’ widget to the sidebar. Paste the shortcode in the ‘Text’ widget and save the changes.
Display WordPress Comment Count without a Plugin
It is possible to display the total number of comments on your WordPress website manually. You have to add a code snipped to the website. Always backup your website before you proceed. Once that is done you should add the following code to the theme’s functions.php file or to the site-specific plugin
function wpb_comment_count() {
$comments_count = wp_count_comments();
$message = ‘There are <strong>’. $comments_count-
>approved . ‘</strong> comments posted by our users.’;
return $message;
}
add_shortcode(‘wpb_total_comments’,’wpb_comment_count’);
With this code, you will get a function that outputs the total number of approved WordPress comments on your website. A shortcode will also be created to display the number of comments. You can use the shortcode [wpb_total_comments] in your pages, posts or text widgets to display the total number of comments.
Display the total number of comments on your WordPress website