Nerd tech, entertainment, and web development blog

WordPress – Separating Comments from Trackbacks and Pingbacks

I don’t know about you, but when I’m reading through comments and see a random link with text around it, it just feels out of place. At first I look at it and think “what the hell is that?” Then once I realize it is a pingback, I just move along. Don’t get me wrong though, I love pingbacks and trackbacks, they are what makes the blogosphere so great.

Just if only there were a way to separate those pingbacks and trackbacks from comments. Oh, wait! There is. The problem though, is that this will only work with a regular template. If you are using the plugin Brian’s Threaded Comments this won’t work. But, since I’m the “nerd that keeps on giving” I’ll set you in the right direction:

Do a search for this within your comments.php:
if($comment_type == 'comment') {
$GLOBALS['comment'] = &$comment;
write_comment($GLOBALS['comment']);
}

(it should be somewhere around line 137 if you didn’t make any changes)

Just after, add:
if($comment_type != 'comment') {
$backlinks = 'true';
}

(there should be another } after the code)

Right before:
<?php else : >
<p><?php _e('No comments yet.'); ?></p>

Add:
<?php
if($backlinks == 'true') {
echo '<h3>Backlinks</h3>';
echo '<ol>';
}
foreach ($comments as $comment) :
$comment_type = get_comment_type();
if($comment_type != 'comment') {
echo '<li>'.get_comment_author_link().'</li>';
}
endforeach;
if($backlinks == 'true') {
echo '</ol>';
}
?>

Of course, you can change <h3>Backlinks</h3> to whatever you want to call it.

This script will automatically add all the trackbacks and pingbacks after all the comments.

Written: Feb 5, 2008


4 Responses to "WordPress – Separating Comments from Trackbacks and Pingbacks"

  • Elite By Design
    February 5, 2008 @ 11:10 pm


    I think I will add this in soon. I agree that it can be frustrating to have pings in the middle of the comments, so thanks for this post! Stumbled.

    • Gary R. Hess
      February 6, 2008 @ 12:31 pm


      Thanks for the stumble, Brian.

  • Internet Entrepreneur
    February 7, 2008 @ 1:02 am


    Hey Gary,

    I want your opinion on this one….

    Is it better to leave the trackback as a comment on the blog, or to delete the trackback?

    I don’t mind the trackbacks from blogs that link to my post. But What I mainly concerned is from scrapers who scrap content and then link back to my blog post. Should I delete it? Ignore it? whats your take on this.

    Here is a link to an example of a trackback that I am referring to. citimastercard.net/scammed-by-an-ebay-member/

    -Jean Costa

    • Gary R. Hess
      February 7, 2008 @ 1:45 am


      Trackbacks don’t necessarily bring quality to your own blog, so if it is spam like a scraper, definitely delete it.

      I let all non-spam trackbacks/pingbacks show. When you show the trackbacks/pingbacks, it is sort of an incentive. Some people, particularly those just starting out like to trackback/pingback to other blogs because it will show somewhere on the page and hope for a click through. It may also give more of an incentive to long-time members to link back because of this.