Site icon Nabtron

Exclude Trackbacks and Pingbacks from Defualt WordPress Recent Comments Widget

The default wordpress recent comments widget shows the most recent comments including the trachbacks and pingbacks too which can be some times annoying or useless in some cases.

So how do we remove/hide these trachbacks and pingbacks from wordpress default recent comments widget? as there is no option in the wordpress admin panel widget manager to set or select what to display in the recent comments widget box and what not to so then what to do now?

Well, the solution is pretty simple. We need to add some code to our functions.php file of the theme.

[This code edit is tested on WordPress (self hosted) version 2.9.2]

Goto

Appearance > Editor

Select the file

functions.php

At the end of the file functions.php add this code (just before the php closing tags ?> :

/* removing pingbacks from recent comments */
if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
$comments = $wpdb->get_results("SELECT $wpdb->comments.* FROM  $wpdb->comments JOIN $wpdb->posts ON $wpdb->posts.ID =  $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND  post_status = 'publish' AND comment_type IN ('comment', '') ORDER BY  comment_date_gmt DESC LIMIT 15");
wp_cache_add( 'recent_comments', $comments, 'widget' );
}

Now save the file. Delete the cache if you are using any cache plugin to see the changes made and then refresh your wordpress website/blog page and you will see that now the recent comments widget shows only the recent comments excluding any pingbacks and trackbacks.

Exit mobile version