Remove Trackbacks from Comment Count in WordPress

December 20, 2012

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;
$get_comments = get_comments('status=approve&post_id=' . $id);

        $comments_by_type = separate_comments($get_comments);

    return count($comments_by_type['comment']);
    } else {

        return $count;

    }

}