Note: For WordPress 2.7 and newer WordPress installations, you’ll instead want to use this tutorial.

With all the WordPress themes available to WordPress users, it always surprises me how these incredible theme authors don’t take a few extra seconds to separate their theme’s trackbacks from the comments. It doesn’t look very professional and it can make it extremely difficult to follow a conversation in the comments.

Separating your trackbacks and comments requires a minimal amount of coding work to set up. First, you’ll want to make a backup of your comments.php file just in case something goes wrong. Next, follow these three steps:

1 ) Access your comments.php file and locate the following code:

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

Immediately after the above code, you’ll want to place this code:

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

2 ) Next, you’ll want to scroll down a little bit and locate the following code:

<?php endforeach; /* end for each comment */ ?>

Immediately before the above code, you’ll want to place this code:

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

This will filter out all of the trackbacks and pingbacks from your main comments loop. Now we need to create a second comments loop to display the trackbacks and pingbacks.

3 ) Almost immediately below the code from step 2 you should find this code:

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

Immediately before the above code, you’ll want to place this code:

<h3>Trackbacks</h3>
<ol>
<?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; ?>
</ol>

You can adjust this code to display how you want to, including using a different header if you have a specific look for your header 3.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Connect with Kyle on Twitter or Google+!

  1. Garry Conn says:

    Great article man. I found it after my friend Kyle from Kyle’s Cove included a reference to it in his article. Nice work man!

  2. Adam says:

    i like the article, but do you know how i can list the number of trackbacks….

    Yours above says 3 Responses…

    Could it say 3 Trackbacks too?

  3. Hack WordPress says:

    Adam – Glad you found the post useful!

    With my current setup, the comments loop starts after it grabs the number of comments from the database, causing it to group the comments and trackbacks into a single total.

    Unfortunately, WordPress handles trackbacks/pingbacks and comments in the same way (which is why you have to approve trackbacks like you would a comment). Therefore, it would be extremely difficult to code your comments.php file to pull them separately.

  4. Jenny says:

    Oh good I’ve been trying to figure out how to do this. Thanks!

  5. Hack WordPress says:

    Jenny – Glad you found it useful!

  6. Adam,
    to count comments and trackbacks separately you should try as follow: immediately after line

    put that code:

    and then simply show right number as number of comments or trackbacks.

  7. ups, it seems that code I wrote isn’t displayed, than again:

    <?php
    $numTrackBacks = 0;
    $numComments = 0;

    foreach ($comments as $comment) {
    if (get_comment_type() != “comment”) { $numTrackBacks++; }
    else { $numComments++; }
    }
    ?>

  8. engtech says:

    Not quite the same thing, but I have two RSS filters for separating my comments and trackbacks in my RSS feeds in NetVibes — so I can always see the last 5 commenters.

    http://internetducttape.com/2007/09/25/blog-maintenance-tip-netvibes-start-page/

  9. This is great stuff. This is by far the esiest to understand WordPress Theme adjusting I have done since I switched to WordPress a few months ago. I’m going through the other articles looking for other golden nuggets of knowledge I can use on my site.

  10. Hack WordPress says:

    Blogger PL – Thanks for contributing the extra code!

    Engtech – That is definitely useful. Thanks for providing the link.

    Michael – Thanks! Hope you check back for future updates.

    Bradly – Glad you found it useful! I try to discuss various news, tips, tricks, hacks, and WordPress plugins/theme reviews, so if you find that stuff useful feel free to subscribe to my feed!

  11. That’s a great workaround and something I’ve just implemented on my site. Thanks for putting it out there.

  12. Vikram says:

    Hey! It works! This mix up of trackbacks and comments was really pissing me off, but this is a great Tutorial, they each have their own territory now!

    Cheers! Great job!

  13. mk says:

    Duh! First of all, thanks for pointing out that this is a themes issue. :-)

  14. Ben K. says:

    Thanks for this one. The Comments/Trackback issue was really bugging me.

  15. Marc says:

    I wanted to separate them but thought it might be too complicated. Thanks for the tip.

  16. jrgd says:

    Thanks for all those explanations: I just did it and it’s quite nice to have trackbacks and comments separated now, I really like it! Thanks!

  17. valmg says:

    Awesome post! Very helpful and looks terrific when implemented. It was easy to put on this blog, I’ll be putting it in place on my others as well. Thanks! Great work!

  18. Adam Kayce says:

    Beautiful! This worked exactly as I wanted it to, even taking out the trackback text, and it did it in about five minutes.

    Thanks so much (you saved my hide).

  19. moserw says:

    Thanks for sharing this. Will check it out.

    http://www.nela.in/

  20. Mac Tips says:

    Is there a way to set it up so it says a line of text if there isn’t any trackbacks. In a similar way to comments. Otherwise a very good tip. Thanks

  21. Monika says:

    is it correct?
    foreach ($comments as $comment) {
    if (get_comment_type() != “comment”) { $numTrackBacks++; }
    else { $numComments++; }
    }

  22. Kevin says:

    Definitely a great help! Simple and clean, thanks.

  23. christine says:

    This is a really great post. Thank you.

    How do you separate Recent Comments from Recent Trackbacks in your sidebar?

    My Recent Comments is now a widget that came with the (Revolution) theme, but it shows the comments and trackbacks all mixed together.

    And even more annoying, it shows trackbacks from internal links between my own articles. Does the code above prevent that? or do you have to somehow exclude it from showing trackbacks where you yourself are the author, or from your own URL, or something like that?

    I’m going to look through your other posts for other good things.
    Thanks again.

  24. Kyle Eslick says:

    @ Christine – If you are already using the Revolution theme, it should be really easy! You use the Recent Comments plugin provided.

    With that plugin you can sensor out internal pings and set up trackbacks to be separate. You should see a trackback tab.

    I’ll put this on my list of posts to tackle in the near future, so subscribe or check back regularly!

  25. christine says:

    Thanks, Kyle.
    I have a Recent Comments widget, but I can’t get in to change anything about it.
    There is no Recent Comments plugin. That one you mentioned sounds excellent. I’ll go look for it, instead of the widget.
    If you know of a good one, could you post a link?
    Thanks again.

  26. christine says:

    I think I found it. It’s called Get Recent Comments, right?
    I wonder if it was there at the start and I somehow lost in during the 2.5 upgrade.
    On the plugin in page, here

    http://blog.jodies.de/archiv/2004/11/13/recent-comments/

    it says “Widget support (but not required)”. What does that mean?

  27. Kyle Eslick says:

    @ Christine – Yes, that is the correct plugin.

    I don’t use widgets, so I think they are just saying widget use isn’t required.

    I will try to get up a plugin review within the next week for this plugin. Hopefully that will give you the information you need. :D

  28. Slave to the Internet says:

    Hey, thanks for this little hack! Works a treat and has really cleaned up my comments!!

  29. ovidiu says:

    hello there.
    I have done things like this mods, but I would want my trackbacks/pingbacks to look more like they look in my comment section of the admin panel, with all that text around the link to my site, not just the link from where they resulted… but when I tried to use $comment->comment_text it gave me noting back :-(

  30. ovidiu says:

    oh and by the way there is a plugin to do this separation: http://www.binarymoon.co.uk/projects/bm-track-ping/

  31. Thanks for the info. I just put it on my blog and love it. I stumbled it and you can count on a trackback!

    What do you think about creating the list, however, below the Submit comment box though?

  32. Kyle Eslick says:

    @ John – That is up to you. I display them just below the comments because it serves as a reminder to readers that they can write about the post on their site and get a link displayed there. I also know they can sometimes generate traffic for people, so I like having them in blue.

  33. Bojhan says:

    How do I remove the Trackback when there are no trackbacks? And dispaly when there are.

  34. Divvy says:

    Great hack, congratulations!!!

    Btw, is there any code that makes possible to not count the trackbacks/pingbacks in the number of comments?

    For example, in a post I have 5 comments.
    1 for a user and 4 trackbacks.
    I only want to show 1 instead of 5.

    Is possible? how? :)

    P.S. I dont know if the “blogger pl dot com” code is correct for me, but I dont know where to put him…

  35. Divvy says:

    blogger pl dot com, where is to put that code?

  36. I can’t do this. Always fail :(

    My comments.php http://josevitor.pastebin.org/51897

    I’m using WordPress Thread Comment plugin.

  37. Lior Iluz says:

    Amazing! greatly appreciated!

  38. avtorentacar says:

    Thank you.

  39. Ron says:

    Can I move the code to display trackbacks before the comments? If so, where would I put it?

  40. Avani-Mehta says:

    Thank you. I could figure out how to not show trackbacks along with comments. Was stuck over how to show them in the end. This makes things quite speedy.

  41. bbrian017 says:

    I did this modification and now comments or my sidebar won’t display using internet explorer can you possibly help me?

    I’m off back to work for the afternoon but if you add me (msn) to the e-mail I’m replying with maybe around 5 this evening you can help me get it right?

    open my url here and use Internet explorer and you will see

    works fine when using firefox!

    p.s. I have subscribed!

  42. bbrian017 says:

    Sorry this works perfect!

    Thanks it was a bad post that messed up the page!

  43. Edward de Leau says:

    Just a note that under 2.7 all of this has changed with the new wp_list_comments

  44. Chetan says:

    Working excellent.
    Thanks a lot.

  45. p@r@noid says:

    Cool Thanks for the tips..Worked for me :)

  46. David Gonzales says:

    Thanks!

  47. Andreas says:

    Thank you for this article. It’s exactly what I’ve searched for!

    Greets

    Andreas

  48. This is working excellent.
    Thanks a lot.

  49. Care Egypt says:

    it’s adorable …
    really thank you so much
    Greeting from Egypt

  50. flapane says:

    Works great, thanks.
    IMHO a nice thing could be deleting the pingbacks from comments count.
    So if there are 4 comments and 3 pings, the post shows: 4 comments, and not 7 comments.

  51. Thanks for the information, now my blog looks better…

  52. bbrian017 says:

    I tried using this with my new theme from elegant theme but no luck yet with the suggested “finds”

    I’ve been waiting weeks for a reply in and attempt inside their forums for the cherrytruffle theme.

    I simply loved this hack it’s by far something that should be added in all wp themes!

  53. nice tip thanks for the tut..

  54. aks says:

    nice tutorial thanks for sharing.

  55. ankara parke says:

    This is great stuff. This is by far the esiest to understand WordPress Theme adjusting I have done since I switched to WordPress a few months ago. I’m going through the other articles looking for other golden nuggets of knowledge I can use on my site.

  56. kapadokya says:

    Beautiful! This worked exactly as I wanted it to, even taking out the trackback text, and it did it in about five minutes.

    Thanks so much (you saved my hide).

  57. Google Experience says:

    This does not work for me. With a pingback all the comments are gone and no way to fill it in. I don’t have any knowledge and I can’t solve this problem… Have to look further for another solution.

  58. Oh good I’ve been trying to figure out how to do this for a customer and it helped me, so thanks for sharing the “tip” :)

  59. CSSReX says:

    Thanks for this wonderful code! My theme was showing track backs in between comments which does not look good. Now its wonderful!
    Thanks once again!

  60. vivek says:

    Works a treat and has really cleaned up my comments!!

  61. Rob Cubbon says:

    I found this really useful as well. Thanks.

  62. Oris WilliamsF1 says:

    I’m going through the other articles looking for other golden nuggets of knowledge I can use on my site.

  63. deepika says:

    can’t this be installed on blogger? :(

  64. rehau says:

    I am using a theme that runs on Thematic so I can find the “foreach” you mentioned but not

Trackbacks/Pingbacks »

  1. Geri izlemeleri yorumlardan ay?r?n, email abonelerinize toplu mesaj gönderin says:
  2. How To Separate Comments and Trackbacks On A WordPress Blog says:
  3. Oddzielamy TrackBacki od komentarzy - Polski Blogger says:
  4. Reader Tips: 21 October 2007 | MegaBlogg Free Blog Host says:
  5. Randy Roedl On Wordpress Blogs says:
  6. GroundFloorSEO.com Syndicated SEO News » Reader Tips: 21 October 2007 says:
  7. How To Separate Comments and Trackbacks On A WordPress Blog | FUN???up UP says:
  8. Cool Links - 10-25-07 says:
  9. Gabfire » Tracbacks and Email subscriptions says:
  10. Tracbacks and Email subscriptions says:
  11. Feedweiser Theme Version 1.0 | Feedweiser says:
  12. 50 tips y trucos para optimizar Blogger y WP | Blog en Serio says:
  13. 25 hacks para dinamizar seu Wordpress! — Bytes a Go-go! says:
  14. Separate WordPress Comments and Trackbacks « weblife says:
  15. Separate WordPress Comments and Trackbacks « ForNext » Learning to be ignorant says:
  16. assembling » Blog Archive » links for 2008-02-04 says:
  17. Wordpress comments, trackbacks and pingbacks | Computer Chit Chat says:
  18. WordPress Trackbacks And Comments | LimeTouch says:
  19. How To Separate Comments and Trackbacks On WordPress : Yeepage says:
  20. 63 essenziali Wordpress Hacks, Tutorials, Help Files e Cheats : technorati.it says:
  21. Wordpress Tutorials/Hacks « The house of software freeware says:
  22. Blog Wordpress, come separare i commenti dai trackback - Geekissimo says:
  23. 20 Places For Wordpress Hacks | Index Blog says:
  24. How to Attract More (Productive) Comments to your Blog Posts | PandemicBlog says:
  25. 155? WordPress ????????????AJAX???…… —— WP ???? | Awesomer says:
  26. Hack WordPress | eVentureBiz Blog - Entrepreneurship and Succeeding Online says:
  27. Guesworld.Com | Graphic is Life says:
  28. To Ping or Not to Ping Your Posts | I'm Blogging That! says:
  29. IndoProTech.com says:
  30. 63 correções, tutoriais, arquivos de ajuda e dicas essenciais para Wordpress | Rafael Bernard Araújo says:
  31. Webmaster’s Blog » Blog Archive » How To Separate Comments and Trackbacks On A WordPress Blog says:
  32. Wordpress Hacks, Guides and Tricks | TechnoBuzz.net says:
  33. WordPress ?? ??? ??? snippet says:
  34. Top 30 Most Wanted Wordpress Tricks and Hacks | Make Money Blogging Experiment says:
  35. Wordpress ile ilgili 155 kaynak « YEAH28 - Her ?ey Sizin ?çin says:
  36. WordPress Developer’s Toolbox | rafdesign says:
  37. Best of WordPress Tutorials – More than 100 recourses | Tutorials | .:Lirent.net Hacks:. | All about Web 2.0, SEO, PHP5, Ajax, Adsense, Unix/Linux, Free Stuff, OpenSource, Designs, Wordpress, Hi-Tech etc says:
  38. How To: Separate WordPress Comments and Trackbacks - 2DP Marketing System Blog says:
  39. Vote for this article at blogengage.com says:
  40. Tired of those ugly trackbacks? - Blog Forum - Bloggeries says:
  41. Links of the Week: December 19th | Bainbridge Studios says:
  42. Resources Every WordPress Theme Developer Should Know About! | Arbenting says:
  43. Introducing Tweetbacks Plugin for Wordpress « ArticleSave says:
  44. Introducing Tweetbacks Plugin for Wordpress | Web Hosting and Domains says:
  45. Wordpress Tema Tasar?mc?lar? ?çin Kaynaklar | Sinerjik Günlük says:
  46. 50???WordPress?? at ?????? says:
  47. Top 50 Wordpress Tutorials says:
  48. Top 50 Wordpress Tutorials | Web Design,Photoshop Tutorial,Design News says:
  49. Threaded Wordpress Comments: The Right Way « Jeremy Poradek says:
  50. Bili?im Mahallesi! » Blog Archive » Wordpress Tema Tasar?mc?lar? ?çin Kaynaklar says:
  51. 10 Extremely Useful WordPress Hacks And Tips | Tweeaks Design says:
  52. 20+ Tutorials For WordPress Theme Developers | oOrch Blog says:
  53. Top 50 Wordpress Tutorials « The Interweb of TJ says:
  54. How to not count number of trackbacks with comments number | reADactor says:
  55. Tutorial: Kommentare und Trackbacks tren… | Wordpress Lesezeichen says:
  56. bulldoggie studio » Top 50 Wordpress Tutorials says:
  57. Top 50 Wordpress Tutorials from TutPlus | WordPress News Magazine says:
  58. top 50 tutorials of wordpress(must use) | Umraz Ahmed | the official site says:
  59. Top 50 Wordpress Tutorials | NetExUrl | Web Development Tutorials & Design Resources says:
  60. 70 Very Useful Wordpress Hacks & Tricks | biroattila.com | Innovation and web says:
  61. Wordpress Hacks « reeboot strategy says:
  62. Wordpress Hacks e Customizations! | sinergie.::.websolution | il blog says:
  63. Geek is a Lift-Style. » Blog Archive » Introducing Tweetbacks Plugin for Wordpress says:
  64. Geek is a Lift-Style. »Archive » Introducing Tweetbacks Plugin for Wordpress says:
  65. 60+ Awesome WordPress Tutorials | The Best WP Themes Online says:
  66. » 50???WordPress?? @ Cloud 1989 says:

Tweetbacks »