Separate Trackbacks and Pings from Comments in WordPress

I had known that the theme I use for this site in WordPress does not separate trackbacks/pings and comments on the post pages. I found this to be annoying because a trackback is not a comment and I want to separate these items. I did some searching and found several examples, but most of them only worked in WordPress 2.7. The examples do not work in the current version of WordPress. This article explains how to do this in the current version of WordPress.

The first thing you will want to do is find this code in single.php:

Replace that code with the following:

<?php comments_template('',true); ?>

Next, open up comments.php and locate this line:

Immediately after that, add the following code:

<?php if (!empty($comments_by_type['comment'])): ?>

Then right before this code:

Add the following:

<?php endif; ?>
		
<?php if (!empty($comments_by_type['pings'])): ?>
				
	<h4 class="content-title" id="comments">Trackbacks &amp; Pings</h4>
			 
	<div>
		 <?php wp_list_comments(
            array(
                'type' => 'pings',
                'callback' => 'tpfunc'
                ); ?>
	</div>
			
<?php endif; ?>

Finally, we need to add a function to functions.php. You can add this anywhere to that file.

<?php
function tpfunc($comment, $args, $depth) 
{
	$GLOBALS['comment'] = $comment; 

	?> 
	<div>
		<div>">
			<div id="trackback">
			%s</cite>'), 
			get_comment_author_link()) ?>
			</div>
		</div>
	</div>
	<?php
	
}

You can move the above code around a little bit, depending on the html in your theme. Following this example will first display comments and then the trackbacks/pings to the post. One thing you will want to do is customize the html/css so that it fits in with your site.

The code provided in this post is based on an article that can be found at Webmaster Index. I changed the code a little bit from what he provided.

Let me know if you found this post useful.

2 thoughts on “Separate Trackbacks and Pings from Comments in WordPress

Comments are closed.