Remove Trackbacks & Pingbacks From Recent Comments

I’ve been trying to reduce the amount of plug-ins on my wordpress blogs for a long time now and so far so good, I’m down to 28 TOTALLY necessary plug-ins. Get Recent Comments by Krischan Jodies unfortunately didn’t make the cut as I decided to use the default Recent Comments widget offered by the WordPress software.

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->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’ );

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)

Thanks to batmoo @ support for this hack.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.


  1. Mk Akan says

    hi chuks…why would you want to remove your ping back and trackback..what happens to people who link to your post…will be shooting your an email for a guest post soon

  2. Sally@bad consolidation credit debt help says

    I have found an increasing amount of trackbacks to my blog lately. It seems like many bloggers have found a plugin that will automatically post these to relevant blogs whenever they do a new post.
    I finally have just turned off this feature.

  3. Udegbunam Chukwudi says

    You guys are getting it all wrong. This fix is not for turning off trackbacks and pingbacks on all posts on your blog. It’s simply for removing them from the recent comments widget which appears in the sidebar (Mine appears @ the bottom).
    .-= Udegbunam Chukwudi hopes you will read…Remove Trackbacks & Pingbacks From Recent Comments =-.

    • Udegbunam Chukwudi says

      I really don’t mind letting you have them but the problem is I’m kinda swamped with blog posts to write, emails etc as this NYSC of a thing draws near. I’ll see what I can do with respects to creating a list of all the plug-ins I use here ;)
      Hope you’re keeping sha? Later

  4. Sally@bad consolidation credit debt help says

    No, understood that. But what I was saying was too many are abusing that on my blog and tryinig to use it to get my site to link back to a site that is not really that good. It seems to be the new form of spam for me.

    • Udegbunam Chukwudi says

      I know get you. I’m TOTALLYfeeling you on this one. I think it was because of trackbacks from such sites that Google reduced my pagerank 6 months ago. I still have trackbacks and pingbacks activated on my blog though I now monitor them and only allow those coming from legitimate sites/blogs to stay ;).
      There are really a new form of spam.

    • Udegbunam Chukwudi says

      LOL. I’m aware 28 plug-ins is much. It’s just that their function @ the moment is TOTALLY indispensable ;)!

  5. Nik From Dedicated Servers Hosting says

    Well, never keep Trackbacks and Pingbacks. We have them when someone refers our post on their blogs but we should also keep in mind that the one who is including our posts in his related posts, he is also ranking higher for the same keywords that we are ranking for and sometimes if our post does not get quickly indexed and the one who has recommended our post, his blog post gets indexed first, our content will be marked as duplicate from search engines.

  6. VPS Hosting says

    I am not sure about the benefit of the trackbacks and pingbacks. Some of the expert bloggers who I know says that trackbacks helps to improve visibility of the blogs, while some says that its useless. They don’t help in your blog SEO at all. Then why wordpress has integrated that feature in wordpress.

  7. Steve says

    Hmmm, I did exactly what you said but it messed up my blog so I had to revert back to the original code. I’m not a techie type but can do anything if the instructions are easy and clear. Are you sure there isn’t something that might be missing from the code you said to copy and paste? Or is there a specific area of the functions.php page that I should paste this into?

    Looking forward to your answer because I really need to remove all those from my Recent Comments list.


    • Udegbunam Chukwudi says

      My internet was acting up but I’ve successfully edited the code in the post above. All you have to do is add it after the last ?> tag in your functions.php file. Make sure to backup before trying out the hack. Cheers

  8. Steve says

    Thanks for adding the missing <?php to the beginning of the code but that still messed everything up and I did exactly what you said. I'm assuming at this point that there is something unique about the theme I'm using that won't allow me to do this hack. Darn! For now I have "unapproved" all my recent trackbacks and pingbacks so they don't appear and dominate my Recent Comments.

    • Udegbunam Chukwudi says

      Sorry to hear that. If you don’t mind I could look through your functions.php for you and try to see if i can add the hack and get it to work on localhost.
      If you’re interested all you have to do is zip your theme and send it to strictlyonlinebiz [at] gmail com and I’ll get back @ you in 24 hours or 1 hour depending on if I’m asleep or my internet connection decides to go bonkers on me again.

      P.S: If your trackbacks and pingbacks are coming from sites that display post experts and then link to your site, I advice you to thread carefully as theycould be spammy.

  9. Kavita says

    I want to know whether this code will function only for recent comments widget you are using or any recent comments widget

    • Udegbunam Chukwudi says

      The code functions for WordPress default recent comments widget. I’m not using any plug-in @ the moment.

Leave a Reply

Your email address will not be published. Required fields are marked *

What is 15 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)