Home WordPress Comment Definition
Definition In WordPress, a comment is a message that a visitor leaves under a post. Your theme shows the comments with a file called comments.php . Inside it you run the comment loop , which means you go through every comment of the post and print it.
The easy way is wp_list_comments() . It prints all comments, with replies and avatars. Show the form with comment_form() . Show a photo with get_avatar() .
Where to use them. Most comment tags work only for the current comment , so use them in a wp_list_comments() callback. Count and link tags, such as comments_number(), go in the post loop. Load comments.php from single.php with comments_template().
Syntax
Syntax A very small comments.php file looks like this:
<?php // single.php ?>
<?php comments_template(); ?>
<?php // comments.php ?>
<?php if ( have_comments() ) : ?>
<ol><?php wp_list_comments(); ?></ol>
<?php endif; ?>
<?php comment_form(); ?> Reference
wp_list_comments() vs Single Comment Tags Both ways show comments. They differ in how much HTML you control.
Way Best for HTML control Example wp_list_comments() The whole list, with replies, classes, and avatars. Little. Change it with options. wp_list_comments( array( 'avatar_size' => 48 ) );wp_list_comments() + callback Your own HTML, with WordPress still handling the nesting. Full control of each comment. 'callback' => 'mytheme_comment'Single tags Printing one piece of data, such as a name, a date, or a message. Full control. comment_author();get_avatar() Showing the commenter's photo. Returns an img tag. Use echo. echo get_avatar( $comment, 48 );
Map
Function Groups at a Glance Pick the group that matches the job, then open the guide you need.
Group Typical job Start here Comment author & identity Show who wrote a comment: name, email, website, IP address, and avatar. comment_author() , comment_author_link() , comment_author_email() , comment_author_email_link() , comment_author_url()Comment content & meta Show the message, date, time, ID, type, and CSS classes of a comment. comment_text() , comment_excerpt() , comment_date() , comment_time() , comment_ID()Reply & form Build the comment form and the Reply and Cancel links. comment_form() , comment_form_title() , comment_reply_link() , cancel_comment_reply_link() , comment_id_fields()Counts, links & navigation Show counts, link to comments, list all comments, and split them into pages. comments_number() , comments_link() , comments_popup_link() , wp_list_comments() , next_comments_link()
Code
WordPress Examples Two short theme examples with sample output.
1. A basic comments.php 2. A custom callback Example 2 — A custom callback Use single comment tags to build your own HTML for each comment.
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
comment_reply_link( array_merge( $args, array(
'depth' => $depth,
'max_depth' => $args['max_depth'],
) ) );
?>
<?php }
// In comments.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>
<a rel='nofollow' class='comment-reply-link' href='...?replytocom=12#respond'>Reply</a>
</li> How It Works WordPress calls your function once for each comment. comment_author(), comment_date(), and comment_text() print the data of that comment.get_avatar() returns the image, so it needs echo. The walker closes the li for you.Continue
Next: WordPress Comment Functions Index After you know the basics, open the functions index for all 30 guides.
Full list: WordPress Comment Functions index (/wordpress/comment/function).
Frequently Asked Questions What is comments.php? It is the theme file that shows the comments of a post and the comment form. WordPress loads it when you call comments_template() in single.php.
What is the comment loop? It is the list of comments of a post. wp_list_comments() runs it for you and prints one item for each comment.
When should I use wp_list_comments()? Use it for the main list. It handles nested replies, classes, and avatars. Add a callback if you want your own HTML.
When should I use single comment tags? Use tags such as comment_author() and comment_text() inside a callback, or in a custom loop where you want full control of the HTML.
How do I show an avatar? Use echo get_avatar( $comment, 48 ). It returns the img tag, so you must echo it.
How do I show the comment form? Call comment_form() after the list of comments. It prints all the fields for you.
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.
11 people found this page helpful
Helpful Share Copy link Suggestion