Clicky

Tutorials

How to display the total number of comments in WordPress

Whenever you read an article, you’ll come across user comments at the bottom of the article. These comments show how engaged the users are with an article. Also, Comments tend to generate more comments. Hence, it is important to display the total number of comments on your blog.

In this article, you’ll learn how to display the total number of comments in WordPress. There are two methods to display the total number of comments. The first method is to display the number of comments by using a plugin and the second method is by using a code.

How to display the total number of comments in WordPress using a plugin?

Displaying the total number of comments using a plugin is quite simple. All you have to do is, install and activate the Simple Blog Stats plugin. After activating the plugin, go to Settings » Simple Blog Stats page to configure plugin settings.

simple blog stats

Simple Blog Stats allows you to display the total number of comments using shortcodes and template tags. Upon clicking on shortcodes, you’ll see all the shortcodes that you can use to show different stats like the total number of comments, registered users, categories, tags, and much more.

Out of the various shortcodes available, copy the [sbs_approved] shortcode to display the total number of comments in WordPress.

simple blog stats shortcode

Use this shortcode in any WordPress page, post, or text widget.

How to display the total number of comments in WordPress using code?

This method of displaying the total number of comments in WordPress requires you to add code to your WordPress files. The code needs to be added in the functions.php file or a site-specific plugin.

01 function wpb_comment_count() {
02
03 $comments_count = wp_count_comments();
04 $message =  'There are '.  $comments_count->approved . ' comments posted on your article.';
05
06 return $message;
07
08 }
09 
10 add_shortcode('wpb_total_comments','wpb_comment_count');
11 add_filter('widget_text','do_shortcode');

A function is created by the above code that outputs the total number of approved WordPress comments on your website. This function creates a shortcode to display it. You can also customize the output message as needed.

After that, use the shortcode [wpb_total_comments] in your WordPress pages, posts, or text widget to display the total number of comments on your site.

Using any of the above two methods, you can display the total number of comments in WordPress. If you know any other ways to do so, share with us in the comment section.

Share this Story
Load More Related Articles
Load More By Editorial Team
Load More In Tutorials

Leave a Reply

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

Join Over 50,000+ Subscribers

Interested In
  •   
  •           
  •                      

Search

WordPress Plugins and Themes