Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

Display the Most Accurate Comment Count in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
Display the Most Accurate Comment Count in WordPress

When you are displaying comment count it is always good to display the accurate comment count. WordPress by default includes your trackbacks and pings into the total count which actually inflates the count. Specially some blogs that does not show trackbacks, or has them separated from the comments, you need to make sure that you are displaying the right count. In this article we will show you how you can display the correct comment count through a small snippet which will filter out trackbacks and pings and only display the actual comment count to your users.

Open your functions.php which is located in your template folder. And Paste the following code in there:

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

With this snippet, you can now show the most accurate comment count to your blog users.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. insitedesignlab says:

    You guys always have the best tutorials. I searched Google for this because my site was prominently displaying inflated comment counts and found exactly what I was looking for!

    Thanks again!

  2. imranansari says:

    This code is helpful.

    I have paste this code in function.php and call this function in my template

    <?php echo comment_count(); ?>


  3. ragnarjoensen says:

    The code only gets my site to crash. Is there a specific place, where the code should be placed? I’m using an Atom framework, if it matters..

  4. Ezuca says:

    I have been searching the web for this solution. Plugins are available but I’m not into it. I tried your code and it works! Thanks a lot.

  5. Tricyclic Antidepressants says:

    Very interesting article and very good blog. Very much interested to know)
    I will add this blog to RSS Reader

  6. Wordpress Developer says:

    I was looking similar a wordpress plugin. This code very useful for me. Thank you.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.