How to Display the Total Number of Comments in WordPress

Do you want to display the total number of comments on your WordPress site?

Comments allow users to participate and engage with the content on your website. By showing off the total comment count, you can encourage more users to join the conversation.

In this article, we will show you how to easily display the total number of comments in WordPress, with or without a plugin.

Display WordPress Comment Count using a Plugin

This method is easier and it is recommended for all users. Instead of writing code, you’ll be using a plugin to display comment count in WordPress.

First, you need to install and activate the Simple Blog Stats plugin. You may read our step by step guide on how to install a WordPress plugin for detailed instructions.

Upon activation, go to Settings Β» Simple Blog Stats page to configure plugin settings.

On this page, you’ll see all the shortcodes that you can use to show different stats like the total number of comments, registered users, number of posts, categories, page count, and more.

You need to copy the shortcode [sbs_approved] to display the total number of approved comments on your WordPress site.

If you want to display it in a post or page, then simply create a new post or edit an existing one.

On the post edit screen, you need to add the shortcode block in the WordPress content editor.

You can do this by clicking on the Add block (+) icon and then search for the shortcode block. Once you find it, you need to click on it to add the shortcode block to the editor.

Next, you need to paste the shortcode [sbs_approved] inside the block settings.

You can add any text you want to display before or after the shortcode.

Alternatively, you can also use the shortcode inside a paragraph block. Simply copy and paste the shortcode where you want to display the comment count.

Using the paragraph block will also allow you to use the text styling option available in the WordPress block editor.

Once you are done, click on the publish or update button to save your changes. You can now visit your website to see your changes in action.

Displaying total comment count in a sidebar widget

You can also use the same shortcode inside a WordPress widget and display it in your blog’s sidebar.

Simply head over to the Appearance Β» Widgets page and add a β€˜Text’ widget to the sidebar.

Next, go ahead and paste your shortcode inside the β€˜Text’ widget.

Don’t forget to click on the β€˜Save’ button to store your widget settings.

You can now visit your website to see the widget in action.

Display WordPress Comment Count (without a plugin)

If you don’t want to use a plugin, then you can use display the total comment count manually.

This method requires you to add a code snippet to your website. If you haven’t done this before, then please check out our guide on how to copy and paste code snippets in WordPress.

Before you do anything, you should make a full backup of your website. This will help you to restore your site in case you break anything while editing the theme files.

Now you need to add the following code to your theme’s functions.php file or a site-specific plugin:

1
2
3
4
5
6
7
8
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');

This code creates a function that outputs the total number of approved WordPress comments on your site. It also creates a shortcode to display it.

You can now use the shortcode [wpb_total_comments] in your posts, pages, or a text widget to display the total number of comments on your website.

This is how it looked on our demo site:

We hope this article helped you display the total number of comments on your WordPress site. You may also want to check out our guide on how to prevent comment spam in WordPress and the best WordPress plugins for every website.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!

Pin It on Pinterest

Add address