Monday, July 8, 2013

How to customize comments markup on your WordPress website

wp_list_comments() function output the entire list of comments for a Post/Page. This doesn't offer much by the way of customizing what HTML markup gets generated for that comment list. To write your own markup for the comment list, you can use a callback function as a parameter in wp_list_comments(), so it's just as nicely abstracted.

Add this php code on your functions.php file of your active theme :

function my_custom_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<?php endif; ?>

// Comments markup code here, e.g. functions like comment_text();

}

Add this code in comments.php file of your active theme :

wp_list_comments("callback=my_custom_comments"); 

Disqus Comments