Family Encyclopedia >> Electronics

Display Accurate WordPress Comment Counts: Exclude Trackbacks and Pings

As experienced WordPress developers, we've optimized countless sites where default comment counts mislead visitors by including trackbacks and pingbacks. This inflates numbers, especially on blogs that hide or separate these from real comments. Our proven snippet filters them out, ensuring users see only genuine comment counts for greater trust and accuracy.

Open your theme's functions.php file and add this reliable code:

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 tweak, battle-tested across production sites, delivers precise comment counts to enhance user experience and site credibility.