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 can 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 on your WordPress website.

How to display total number of comments in WordPress

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

This method is easier and is recommended for all users. Instead of writing code, you’ll be using the Simple Blog Stats plugin to show the comment count in WordPress.

However, just be aware that this plugin 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’ll 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, go to Settings » Simple Blog Stats to configure plugin settings.

Simple Blog Stats Plugin settings page

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, and more.

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

If you want to show the total number of comments on a page or post, then simply create a new post or edit an existing one.

Then, 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 [sbs_approved] 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 formatting settings. For example, you might make it bold or italic.

When you’re finished, click on the publish or update button to save your changes. You can now visit your website to see your changes in action.

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 this number across your entire WordPress website, as you can see in the following image.

How to display the total WordPress comment count in a sidebar

You can find your widget area by going to Appearance » Widgets.

Here you’ll see a list of all the available widget areas. For example, in the following image we’re using the ThemeIsle Hestia Pro theme, and you can see it has multiple areas where you can add widgets, including the sidebar, header, and footer.

Adding the total comment count to a widget-ready area

The areas you can place widgets 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, add it to the area where you want to show the comment count.

Adding the comment count shortcode to a WordPress widget

You can now paste the [sbs_approved] into the widget and type in any text that 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.

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

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

Typically, you would need to add custom code snippets to your 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’ll see all the ready-made snippets that you can add to your site using WPCode.

Since we’re creating our own snippet, hover your mouse over ‘Add Your Custom Code,’ and then click ‘Use snippet.’

Showing the most accurate WordPress comment count using WPCode

To start, enter a title for the custom code snippet. This can be anything that helps you identify the snippet.

Once you’ve done that, open the ‘Code Type’ dropdown and choose ‘PHP Snippet.’ Next, paste the following snippet into the code 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');

Below the code box, you’ll see some insertion options.

To use the shortcode on any page, post, or widget-ready area, open the ‘Location’ dropdown menu and select ‘Run Everywhere.’

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.

How to save the total comment count 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.

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

3 CommentsLeave a Reply

  1. 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


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.