Removing <li> from Comment

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:

Read More
</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'); ?>
            </aside>
            <?php comment_text(); ?>
        </div>

        <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>
            <div class="comment-reply">
                <?php comment_reply_link( array_merge( $args, array( 'reply_text' => 'Reply to Comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
            </div>
        </div>
    </article>
</section>

Related posts

1 comment

  1. 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():

    wp_list_comments(
        array (
            'walker' => new WPSE_127257_Walker_Comment
        )
    );
    

Comments are closed.