Excluding pingbacks and trackbacks from the WordPress comment count

If you want to have pingbacks and trackbacks enabled in the admin area, but not display them in your WordPress theme, you’ll also need to make sure they don’t show up in any of the comment counts. To do this, you’ll need to add a “get_comments_number” filter in functions.php, and pass it a custom function that will override the default comments count.

If the WordPress theme you’re editing doesn’t have a functions.php file, create it in the theme’s root directory. Add the following code to functions.php:

 * Don't count pingbacks or trackbacks when determining
 * the number of comments on a post.
function comment_count( $count ) {
	global $id;
	$comment_count = 0;
	$comments = get_approved_comments( $id );
	foreach ( $comments as $comment ) {
		if ( $comment->comment_type === '' ) {
	return $comment_count;

add_filter( 'get_comments_number', 'comment_count', 0 );

So, what’s going on here? We’re getting the approved comments for a given post ID and then looping through them, checking to see if the comment is an actual comment (the empty comment type). If the comment is not a pingback or trackback, we increment a counter variable. This counter variable is returned after we’re finished looping through all of the approved comments, and it represents the number of comments.

Technique from wp_guy on the WordPress support forum thread “How do I NOT count number of trackbacks/pingbacks with comments_number?

3 thoughts on “Excluding pingbacks and trackbacks from the WordPress comment count

  1. A huge thanks to the author (and wp_guy) for the snippet, and another “thank you” to Matthew Campagna for his addition. ‘Fixed my problem!

Leave a Reply