WordPress wp_list_comments() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Template tag

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.

WordPress
wp_list_comments();
wp_list_comments( array( 'style' => 'ol', 'avatar_size' => 48 ) );
wp_list_comments( array( 'callback' => 'mytheme_comment' ) );
CallWhat 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
WordPress
wp_list_comments( string|array $args = array(), WP_Comment[] $comments = null ): void|string

Parameters

ParameterDescription
$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 ValueDescription
void|stringPrints 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.

Example 1 — Default list

Print the list in comments.php.

WordPress
<?php if ( have_comments() ) : ?>
  <ol class="comment-list">
    <?php wp_list_comments( array( 'style' => 'ol', 'avatar_size' => 48 ) ); ?>
  </ol>
<?php endif; ?>

How It Works

  1. have_comments() checks that the post has comments.
  2. wp_list_comments() prints one li per comment.
  3. avatar_size sets the avatar size in pixels.

Example 2 — Custom callback

Control the HTML of each comment with comment tags.

WordPress
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' ) );

How It Works

  1. WordPress calls mytheme_comment() for each comment.
  2. Comment tags print the data of the current comment.
  3. The walker adds the closing </li> after any replies.

Example 3 — Only comments

Show normal comments only, and a limit of three levels.

WordPress
<?php
wp_list_comments( array(
  'type'      => 'comment',
  'max_depth' => 3,
  'style'     => 'div',
) );
?>

How It Works

  1. type set to comment hides pingbacks and trackbacks.
  2. max_depth limits how deep replies can go.
  3. style set to div prints div tags instead of li.

Frequently Asked Questions

It prints the list of comments of the current post, including nested replies.
In comments.php, inside a ul or ol tag when style is ul or ol.
Pass a callback function in the arguments array.
Use wp_list_comments() to loop. Use the single tags, such as comment_author(), inside your callback.
Pass 'type' => 'comment'.

Back to the Function Index

See every WordPress comment function in simple tables.

Comment Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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