Example 1 — Default text
Print the default text.
<span class="count"><?php comments_number(); ?></span> How It Works
- The post has three comments.
- WordPress prints the default text for more than one.
- The number replaces the percent sign.

In WordPress, comments_number() prints the number of comments of a post as text, such as 3 Comments.
You can set the text for no comments, one comment, and more than one comment. Use % in the last text where the number should go.
Call it with no text for the defaults, or set your own texts.
comments_number();
comments_number( 'No replies', 'One reply', '% replies' ); | Call | What it does |
|---|---|
comments_number() | Prints the count with default text, such as 3 Comments. |
comments_number( 'No replies', 'One reply', '% replies' ) | Prints your own text for 0, 1, and more. |
get_comments_number() | Returns the count as a number. |
Use get_comments_number() when you need the number for a condition.
comments_number( string|false $zero = false, string|false $one = false, string|false $more = false, int|WP_Post $post = 0 ): void | Parameter | Description |
|---|---|
$zero | Optional. Text when there are no comments. Default No Comments. |
$one | Optional. Text when there is one comment. Default 1 Comment. |
$more | Optional. Text when there are more comments. Use % for the number. Default % Comments. |
$post | Optional. A post ID or WP_Post object. Default is the current post. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the text. |
Three short theme examples. Each one has a sample output.
Print the default text.
<span class="count"><?php comments_number(); ?></span> Use your own words for each case.
<p><?php comments_number( 'No replies yet', 'One reply', '% replies' ); ?></p> % replaced by the number.Use get_comments_number() in a condition.
<?php if ( get_comments_number() > 0 ) : ?>
<h2><?php comments_number(); ?></h2>
<?php endif; ?> get_comments_number() returns a number.comments_number() prints the text.Print a link to the comments of a post, with the count as text.
14 people found this page helpful