Customise Comments

How To Separate Comments And Trackbacks With WordPress


By default WordPress themes will display trackbacks and comments together at the bottom of the post, but you don't really want to display these together it's much better if you can separate these.

If you can separate them then visitors can just see all the comments in order and then you can have the trackbacks after these so you are still encouraging people to link to your site.

Use the following code and you will be able to use these separately.

Just Display Comments

To just display the comments use the following code.


<?php foreach ($comments as $comment){

     if(get_comment_type() == "comment") {

          echo '<li>'.comment_text().'</li>';

} ?>

Just Display Trackbacks

To just display the trackbacks use the following code.


<?php foreach ($comments as $comment){

     if((get_comment_type() == "pingback") || (get_comment_type() == "trackback")) {

          echo '<li>'.comment_author_link().'</li>';

} ?>
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial