How to display the total number of comments in WordPress

Are you looking for a way to display the total number of comments on your WordPress site? Showing your comment count can inspire more users to join in on the conversation. Apart from that, a high comment count usually indicates engaging content that is interesting to read. This article illustrates the method to display the total number of comments in WordPress.

Method 1: Using a Plugin to display the total number of comments in WordPress

Using a Plugin to display the total number of comments in WordPress is an easy and recommended solution for all users. Here is how you can do it:

  1. Install and activate the Simple Blog Stats plugin.
  2. Go to Settings >> Simple Blog Stats page. You can now configure the plugin settings.

The plugin shows your blog stats with the help of template tags and shortcodes. This page lists all the shortcodes that you can use to show different stats data in your blog. You can choose to view the total number of comments, categories, tags and registered users of your blog.

To display the total number of comments in WordPress, you need to copy the shortcode [sbs_approved]. This shortcode can be used in any WordPress page, post, or text widget.

Method 2: Adding code to display the total number of comments in WordPress

Adding code to your WordPress files can also help you display the total number of comments in your WordPress site. To display the comment count in WordPress using code: 

1.Add the following code to your theme’s functions.php file.

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'); 
add_filter('widget_text','do_shortcode'); 

This code creates a function that generates an output of the total number of approved WordPress comments on your site. It also creates a shortcode to display the number of comments. You can choose to customize the output message if needed.

2. Use the shortcode [wpb_total_comments] in your WordPress pages, posts or text widget.

The above method successfully displays the total number of comments on your site.

This is how the output appeared in our demo site.

For further questions, or if you need help, please open a support ticket from your HostPapa Dashboard. Click here to learn how to do it.

Related Articles