Separate Trackbacks from Comments on Your WordPress Blog


background image

I wonder why WordPress theme designers don’t implement this feature more often. Separating trackbacks from comments is a very simple tweak that will greatly improve the user experience for the people that comment or read comments on your blog. If you keep them together (as I used to until recently…) the readers will see a bunch of links and snippets of code mixed with the real comments, making it difficult to follow the conversation.

So how do you do it? You will just need to open the comments.php file and edit some lines. Michael from Pro Blog Design has a step by step tutorial for this purpose, and he allowed me to adapt it here.

First of all locate the following line inside your comments.php file (which is located under “Presentation” and then “Theme Editor” on your WordPress control panel).

<?php foreach ($comments as $comment) : ?>

Right after that line, paste the following code:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

These lines will identify the type of the comment in question, and it will only publish real comments, while filtering trackbacks and pingbacks. Now you will need to close the PHP function, so again look for the following line:

<?php endforeach; /* end for each comment */ ?>
Before that line paste the following code:

<?php } /* End of is_comment statement */ ?>

That is it; you are now filtering out all the trackbacks and pingbacks. Some people consider it better to remove trackbacks altogether since they are often target of spammers. I don’t agree with this solution. Trackbacks are an essential part of the blog world, just improve your spam blocking tools and you should be fine.

The question then becomes: should I place the trackbacks before or after the comments? Both methods can work, depending on what you are trying to accomplish. Placing the trackbacks right after the post (and before the real comments) might encourage people to link to your posts since their trackback links will be displayed prominently. Placing the comments first, on the other hand, will encourage readers to leave more comments and to follow the conversation more closely.

The code to add a “Trackbacks” section is the following:
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>

Notice that you can customize the title (“Trackbacks,” “Backlinks,” “Blog Reactions” and so on), the header tag (H1, H2, H3 and so on and the list type (ordered or unordered).

Now, if you want to insert the “Trackbacks” section before the real comments you will need to paste that code after the comments header, which looks like this:

<h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h2>

You might also want to add another header before the real comments to call them out.

Finally, if you want to place the “Trackbacks” section after the real comments just paste the code before this line:

<?php else : // this is displayed if there are no comments so far ?>

Browse all articles on the WordPress category or check the recommended articles for you below:

64 Responses to “Separate Trackbacks from Comments on Your WordPress Blog”

  • Adam Cleaner

    salenco: unfortunately it seems this method is no longer a solution as worpdress has changed the way it works in 2.8.4. i wish this article would have the date it was posted as then it would be obvious if something was a little old or not

  • Sapan

    Thanks a lot for this useful tutorial…

    It did the work for me.. 🙂

  • salenco

    Nice tutorial, but I can´t find in comments.php. I´m using WordPress 2.8.4 with the last Cutline template with one right column.

    Thanks for reading.

  • thelongmile

    Thank you so much! this has helped me solve a long standing problem on a theme I’m developing with on my testing server

  • joyologo design shop 2.0

    really helpful post thanks a lot..

  • Daniel Brauer

    What is captcha code?, pls provide me captcha code codes or plugin, Thanks in advance.

  • Hikari

    VERY nice!

    I was gonna implement this on my theme but when I looked it was already implemented! 😀

    I think nobody trackbacked me at all :/

  • paul

    Have tried trackbacks and they worked for me.Try today

  • Ken

    Something has changed since the WordPress 2.7….

  • Geoserv


    I definitely agree with this. Nothing worse than trying to read comments and having to wade through trackbacks.

    Submitted this post to:

  • todotuto

    Excuse-me, false alarm, the problem was another one.

  • todotuto

    In one of my blogs I have implanted east code and I have had it to clear because it gave a problem me in post that has 103 commentaries, was not finished loading the page. 🙁

  • Rajaie

    Your blog is a perfect example

Comments are closed.