comments_number( string|false $zero = false, string|false $one = false, string|false $more = false, int|WP_Post $post )

Displays the language string for the number of comments the current post has.


$zero string|false Optional
Text for no comments.

Default: false

$one string|false Optional
Text for one comment.

Default: false

$more string|false Optional
Text for more than one comment.

Default: false

$post int|WP_Post Optional
Post ID or WP_Post object. Default is the global $post.

Top ↑


File: wp-includes/comment-template.php. View all references

function comments_number( $zero = false, $one = false, $more = false, $post = 0 ) {
	echo get_comments_number_text( $zero, $one, $more, $post );

Top ↑


Version Description
5.4.0 The $deprecated parameter was changed to $post.
0.71 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Text Response to Number of Comments

    Displays text based upon number of comments: Comment count zero – no responses; comment count one – one response; more than one comment (total 42) displays 42 responses.

      This post currently has
      <?php comments_number( 'no responses', 'one response', '% responses' ); ?>.
  2. Skip to note 2 content
    Contributed by Codex

    Title For Comments Section

    You might want to have a title above your comments section that includes the number of comments. This example shows how to do that and have all the strings also be translatable.

    printf( _nx( 'One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'textdomain' ), number_format_i18n( get_comments_number() ) );
  3. Skip to note 3 content
    Contributed by MakeWebBetter

    Usage of ‘comments_number’ filter

    add_filter( 'comments_number', 'wporg_com_num', 10, 2 );
    function wporg_com_num ( $out, $num ) { // Two parameter as in filter described
        if ( 0 === $num ) { 
            $out = '0 Comments'; // If No comments
        } elseif ( 1 === $num ) {
            $out = '1 Comment'; // If 1 comment
        } else {
            $out = $num . ' Comments'; // More than 1 comment
        return $out;

You must log in before being able to contribute a note or feedback.