Remove Trackbacks and Pingbacks from Comments

/Remove Trackbacks and Pingbacks from Comments

Unfortunately, the default Recent Comments widget also includes trackbacks and pingbacks and the sight ain’t so lovely thus I had to add this hack to weed out the trackbacks and pingbacks.

Open your theme’s functions.php file and add the following code

if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
    $comments = $wpdb-&gt;get_results("SELECT $wpdb-&gt;comments.* FROM $wpdb-&gt;comments JOIN $wpdb-&gt;posts ON $wpdb-&gt;posts.ID = $wpdb-&gt;comments.comment_post_ID WHERE comment_approved = '1' AND post_status = 'publish' AND comment_type IN ('comment', '') ORDER BY comment_date_gmt <span style="color: #ff0000;">DESC LIMIT 15</span>");
    wp_cache_add( 'recent_comments', $comments, 'widget' );

Please note that the value red (DESC LIMIT 15) controls how many recent comments will appear in your sidebar and the order with which they will appear (ASC or DESC)

2011-03-02T23:20:07+00:00June 7th, 2010|PHP Snippets|2 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.


  1. Warren Chandler March 5, 2011 at 3:12 am - Reply

    This is Facebook me commenting!

  2. Clare Brown March 6, 2011 at 10:51 pm - Reply

    And me!

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.