Display the Most Accurate Comment Count in WordPress348

Display-the-Most-Accurate-Comment-Count-in-WordPress
Author: InfoBeep - December 3, 2017 | subject to copyright

You must be wondering why to display comment count in WordPress, but the fact is displaying comment count actually helps you to identify your blog popularity. Now, if you have changed your mind and thinking to display actual comment count by filtering trackbacks and pings.

Procedure

Open functions.php file and paste the code below:

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

functioncomment_count( $count) {

if( !is_admin() ) {

global$id;

$comments_by_type= &separate_comments(get_comments('status=approve&post_id='. $id));

returncount($comments_by_type['comment']);

} else{

return$count;

}

}


Note: this code will help you get the most accurate comment count of your blog.