Home WordPress Comment Functions wp_list_comments() Definition In WordPress, wp_list_comments() prints the list of comments for the current post. It handles nested replies, odd and even classes, and avatars for you.
It is the main function in comments.php. Use it for the full list, and use a callback when you want to control the HTML of each comment with tags like comment_author().
Syntax Call it with no arguments for the default list, or pass an array of options.
wp_list_comments();
wp_list_comments( array( 'style' => 'ol', 'avatar_size' => 48 ) );
wp_list_comments( array( 'callback' => 'mytheme_comment' ) ); Call What it does wp_list_comments()Prints the default list of comments. wp_list_comments( array( 'avatar_size' => 48 ) )Prints the list with 48 pixel avatars. wp_list_comments( array( 'callback' => 'mytheme_comment' ) )Uses your own function for each comment.
Common keys are style, avatar_size, max_depth, type, callback, short_ping, and echo.
Full declaration wp_list_comments( string|array $args = array(), WP_Comment[] $comments = null ): void|string Parameters Parameter Description $argsOptional. An array of options. Keys include style (ul, ol, div), avatar_size, max_depth, type (all, comment, pings), callback, short_ping, and echo. $commentsOptional. An array of comment objects. Default is the comments of the current post.
Return Value Return Value Description void|string Prints the list by default. With 'echo' => false, it returns the HTML as a string.
WordPress Examples Three short theme examples. Each one has a sample output.
1. Default list 2. Custom callback 3. Only comments Example 1 — Default list Print the list in comments.php.
<?php if ( have_comments() ) : ?>
<ol class="comment-list">
<?php wp_list_comments( array( 'style' => 'ol', 'avatar_size' => 48 ) ); ?>
</ol>
<?php endif; ?> <ol class="comment-list">
<li id="comment-12" class="comment even thread-even depth-1">
<article class="comment-body">
...
</article>
</li>
</ol> How It Works have_comments() checks that the post has comments.wp_list_comments() prints one li per comment.avatar_size sets the avatar size in pixels.Example 2 — Custom callback Control the HTML of each comment with comment tags.
function mytheme_comment( $comment, $args, $depth ) { ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<?php echo get_avatar( $comment, 48 ); ?>
<strong><?php comment_author(); ?></strong>
<small><?php comment_date(); ?></small>
<?php comment_text(); ?>
<?php }
wp_list_comments( array( 'callback' => 'mytheme_comment' ) ); <li class="comment even thread-even depth-1" id="comment-12">
<img alt='' src='https://secure.gravatar.com/avatar/abc123?s=48' class='avatar avatar-48 photo' height='48' width='48'/>
<strong>Jane Doe</strong>
<small>November 12, 2026</small>
<p>Thanks, this helped me a lot!</p>
</li> How It Works WordPress calls mytheme_comment() for each comment. Comment tags print the data of the current comment. The walker adds the closing </li> after any replies. Example 3 — Only comments Show normal comments only, and a limit of three levels.
<?php
wp_list_comments( array(
'type' => 'comment',
'max_depth' => 3,
'style' => 'div',
) );
?> <div id="comment-12" class="comment even thread-even depth-1">...</div>
<div id="comment-13" class="comment odd alt depth-2">...</div> How It Works type set to comment hides pingbacks and trackbacks.max_depth limits how deep replies can go.style set to div prints div tags instead of li.Frequently Asked Questions What does wp_list_comments() do? It prints the list of comments of the current post, including nested replies.
Where do I use it? In comments.php, inside a ul or ol tag when style is ul or ol.
How do I change the HTML of each comment? Pass a callback function in the arguments array.
Do I use wp_list_comments() or single comment tags? Use wp_list_comments() to loop. Use the single tags, such as comment_author(), inside your callback.
How do I hide pingbacks? Pass 'type' => 'comment'.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
13 people found this page helpful
Helpful Share Copy link Suggestion