I'm making a custom comment template, and I do not wish to use a list to display comments.

By default, WordPress puts the following at the end of every comment:

</li><!-- #comment-## -->

I know I could hack the core wp-includes/comment-template.php, but that would leave me to not be able to update normally. Is there a way to remove this?

Here's my functions callback:

<section id="li-comment-<?php comment_ID(); ?>">
    <article id="comment-<?php comment_ID(); ?>" class="comment <?php if ($comment->comment_author_email == get_the_author_email()) { echo 'author-comment'; } ?>">

        <div class="comment-content">
            <aside class="comment-gravatar">
                <?php echo get_avatar($comment, '50'); ?>
            <?php comment_text(); ?>

        <div class="comment-data">
            <div class="comment-author">
                <p>Posted by : <?php echo get_comment_author(); ?></p>
                <p>On <?php the_time('l, F jS, Y') ?>  at <?php the_time() ?></p>
            <div class="comment-reply">
                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => 'Reply to Comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>

wp_list_comments() accepts a walker in the array of its first parameter. This is a class that renders the output. If you don’t provide one, the default class will be used, Walker_Comment. You can find it in wp-includes/comment-template.php.

To change the complete comment list out, create a custom walker in your functions.php which extends the default class:

class WPSE_127257_Walker_Comment extends Walker_Comment
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        // do nothing.
    function end_lvl( &$output, $depth = 0, $args = array() ) {
        // do nothing.
    function end_el( &$output, $comment, $depth = 0, $args = array() ) {
        // do nothing, and no </li> will be created
    protected function comment( $comment, $depth, $args ) {
        // create the comment output
        // use the code from your old callback here

And then you use that class when you call wp_list_comments():

    array (
        'walker' => new WPSE_127257_Walker_Comment
| improve this answer | |
  • Worked great, I appreciate your help. I have an understanding of php and classes, but your comments are appreciated as well. – MrJustin Dec 21 '13 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.