WordPress Wednesday: Customizing Comment Output

Geek Factor: 3

The output for WordPress comments is generated by using the wp_list_comments() function, but actually editing the markup used by the comments is a little tricky. If you needed to add, say, an extra <div> to get your design to work, you’ll find that there isn’t actually a theme file you can edit.

Here is a handy snippet I ran across on the WordPress Support Forum when trying to solve this issue on a recent project.

First, in your functions.php you will need to write out the code you’d like to use as your comment output. The example below just adds a couple containing elements to the original code, but you can add anything you need:

[php] //custom comment layout function custom_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?>
  • id="li-comment-">
    comment_author_email, 48 ); ?> %s'), get_comment_author_link()) ?>
    $depth, 'max_depth' => $args['max_depth']))) ?>
    comment_approved == '0') : ?>

  • Then when generating the output, edit the wp_list_comments() function to reference the name of your function:


    Because it’s necessary to specify the name of your custom comment function each time you use it, you can make more than one should you need it.

    Leave a Comment

    Note: Fields marked with a * are required; email addresses are not published.

    Legal FAQ Collections