Custom WordPress Comments Template

This was originally posted by me on Castle Made – however, I thought I would repost this popular post before removing Castle Made.

The default template will have all the usual details. Username, gravatar and comment etc. The issue isn’t the content (unless you care about the format of the date to match the rest of your website) – the issue is the layout.

By adding some code to the functions.php file in your WordPress theme folder, you can have more control over what is going on. The following is the template used on Castle Made.

<?php
function cust_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>" class="aComment">
	<div class="commenter">
		<div class="gravatar">
			<?php echo get_avatar($comment,$size='140'); ?>
		</div>
		<?php printf(__('<h4><cite class="author">%s</cite></h4>'), get_comment_author_link()) ?>
		<div class="comment-meta commentmetadata"><?php printf(__('%1$s'), get_comment_date(), get_comment_time()) ?></div>
	</div>
	<div class="theComment">
	<?php comment_text() ?>
	<?php if ($comment->comment_approved == '0') : ?>
	<p><em><?php _e('Your comment is awaiting moderation.') ?></em></p>
	<?php endif; ?>
	</div>
</div>
<?php } ?>

The important part is to now trigger the template change. Open up your theme’s comments.php file, and go to line 29 (default theme) and look for the following code:

<?php wp_list_comments(); ?>

And change it to the following:

<?php wp_list_comments('callback=cust_comment'); ?>

The value of ‘callback’ must match the name of your comments function.