Remove Trackbacks from Comment Count in WordPress

Are you finding that your comment count in WordPress not the correct number? Adjusting the settings in the discussions screen still doesn’t fix it. Well, this little snippet of PHP added to your functions.php file should fix that.

Add this snipper to your functions.php file to tweak the comment count to not show trackbacks.


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;
 
 }
}

This post currently has no responses. What do you think?

You can use basic HTML when posting code, please turn all < characters into &lt; or > into &gt;
If the code is multi-line, use <pre><code></code></pre>

*