Beginner's Guide for WordPress / Start your WordPress Blog in minutes

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 are the main way that users engage with your content. By showing off the total comment count, you can encourage more people to join the conversation.

In this article, we will show you how to easily display the total number of comments on your WordPress website.

How to display total number of comments in WordPress

Why Display the Total Number of Comments in WordPress?

An active comment section can improve the visitor experience, create a sense of community, and keep people on your website for longer. Some people may even come back to a page or post just to read the latest comments.

You will want to do everything you can to get more comments on your WordPress posts. To start, we recommend allowing users to subscribe to comments and asking a question at the end of each post to encourage debates.

You can also show the total comment count. A higher number will make visitors want to join in the conversation. It’s also a form of social proof, as readers may visit your posts just to see why so many people are commenting.

With that being said, let’s see how you can display the total number of comments in WordPress. Simply use the quick links below to jump straight to the method you want to use.

Method 1: Display WordPress Comment Count Using a Plugin (Easy)

The easiest way to show an accurate comment count is by using Simple Blog Stats. This plugin shows the total number of approved comments and comments in moderation. However, it doesn’t include pings and trackbacks in its count.

Many websites turn off trackbacks and pingbacks in an attempt to block spam comments in WordPress, so this may not be a big problem for your website.

However, if you want to include trackbacks and pings in your total comment count, then we recommend using method 2 instead.

To get started with this method, you will need to install and activate the Simple Blog Stats plugin. If you need help, then please see our guide on how to install a WordPress plugin.

Upon activation, you can see all the plugin’s shortcodes by going to the Settings » Simple Blog Stats page.

The Simple Blog Stats WordPress plugin

Here, simply click to expand the ‘Shortcodes’ section.

You will now see all the shortcodes you can use to show different stats like the total number of comments, registered users, number of posts, categories, and more.

How to show the total number of comments in WordPress

To show the total count of all approved comments on your WordPress blog, simply use the following shortcode: [sbs_approved]

If you want to show the total number of approved comments plus comments that are still in the WordPress comment moderation queue, then you can use [sbs_comments] instead.

When you have the shortcode you want to use, simply go to the page or post where you want to show the total number of comments.

Here, click on the ‘+’ button to add a new block. You can now start typing ‘Shortcode’ and select the right block when it appears.

Add Shortcode Block to a WordPress Page

Next, simply paste the shortcode into the block.

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

Paste Shortcode to the Shortcode Block

Another option is to use the shortcode inside a paragraph block.

Simply add the shortcode where you want to show the total comment count.

Paragraph block with comment count shortcode inside it

Using the paragraph block also allows you to style the total comment count using the standard text formatting settings. For example, you might make it bold or italic, or change the text color.

When you are finished, click on the ‘Publish’ or ‘Update’ button to save your changes. You can now visit your website to see the comment count live.

Comment count displayed in a WordPress post

Displaying Total Comment Count in a Sidebar Widget

You can also add the total comment count to a sidebar or similar section using the same shortcode. This is an easy way to display the comment count across your entire WordPress website, as you can see in the following image.

How to display the total WordPress comment count in a sidebar

To add the comment count to a sidebar or similar section, go to Appearance » Widgets.

Here you will see a list of all the available widget areas. For example, in the following image, we are using the ThemeIsle Hestia Pro theme, which has multiple widget-ready areas, including the sidebar, header, and footer.

Adding the total comment count to a widget-ready area

The widget-ready areas are defined by your WordPress theme, so you may see something different depending on the theme you’re using.

Now, click on the blue ‘+’ button and type in ‘Paragraph.’ When the Paragraph widget shows up, drag it to the area where you want to show the comment count.

Adding the comment count shortcode to a WordPress widget

You can then paste the [sbs_approved] shortcode into the widget and type in any text you want to show before or after the total comment count.

When you’re finished, click on ‘Update’ to store your changes.

Creating a total comment count widget

Now, if you visit your website you’ll see the total comment count widget in action.

Note: If you’re using a block-based theme, then you can edit your site’s widget-ready areas by going to Themes » Editor.

Method 2: Display Comment Count Using Code (Most Accurate)

If you want to include pingbacks and trackbacks in the total comment count, then you will need to add custom code to your website.

Often, tutorials will ask you to add custom code snippets to the theme’s functions.php file. However, we don’t recommend this method as even a small mistake in your code could cause a number of common WordPress errors or even break your site entirely.

That’s why we recommend using WPCode. It allows you to add custom code in WordPress without having to edit any core WordPress theme files.

The first thing you need to do is install and activate the free WPCode plugin on your website. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, go to Code Snippets » Add Snippet.

How to show the total comment count using code

Here, you will see all the ready-made snippets that you can add to your site using WPCode. This includes code that allows you to disable attachment pages, upload SVG files, disable automatic updates, and more.

To create your own snippet, hover your mouse over ‘Add Your Custom Code,’ and then click the ‘Use snippet’ button underneath.

Showing the most accurate WordPress comment count using WPCode

To start, enter a title for the custom code snippet. This is just for your reference, so it can be anything that helps you identify the snippet.

Once you’ve done that, open the ‘Code Type’ dropdown and choose the ‘PHP Snippet’ option. Then, paste the following snippet into the ‘Code Preview’ editor:

function wpbeginner_comment_count() { 
   
function comment_count( $count ) {
    if ( ! is_admin() ) {
        $comments_by_type = &separate_comments(get_comments('status=approve'));
        return count($comments_by_type['comment']);
    } else {
        return $count;
    }
}
add_filter('get_comments_number', 'comment_count', 0);
   
$actual_comment_count = get_comments_number(); 
   
return $actual_comment_count;
   
}
   
add_shortcode('actual_comment_count', 'wpbeginner_comment_count');

Here’s what it should look like:

Paste code and select PHP Snippet as the code type

Below the code box, you’ll also see some insertion options. Select the ‘Auto Insert’ option to have the snippet automatically inserted and executed on your site.

Adding comment code to your entire WordPress website

After that, scroll to the top of the screen and click on the ‘Inactive’ toggle so it shows ‘Active.’

With that done, click on ‘Save snippet’ to make the comment snippet live.

Activate and save your custom code snippet

You now have a shortcode that you can use to show the total number of comments on your website, including trackbacks, pings, and unapproved comments.

Simply add the [actual_comment_count] shortcode anywhere you want to show the total comment count. For more information on how to place the shortcode, please see our guide on how to add a shortcode in WordPress.

We hope this tutorial helped you learn how to display the total number of comments in WordPress. You may also want to learn how to create an email newsletter and the best social media plugins for WordPress.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

4 CommentsLeave a Reply

  1. Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Thanks for this simple hack, can I show this just at the beginning of every post automatically?

    • If you set up a widget area you certainly could automatically add it to the start of all of your posts

      Admin

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.