apply_filters( ‘comments_number’, string $comments_number_text, int $comments_number )

Filters the comments count for display.

Description

See also

Parameters

$comments_number_textstring
A translatable string formatted based on whether the count is equal to 0, 1, or 1+.
$comments_numberint
The number of post comments.

Source

return apply_filters( 'comments_number', $comments_number_text, $comments_number );

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    WordPress hooks provide a powerful way to modify and extend the core functionality of your site. The apply_filters function is used to apply filters to a variable, allowing you to modify data before it is used. The comments_number filter specifically allows you to alter the text that displays the number of comments before it is shown on the site.

    function wpdocs_comments_number_filter( $comments_number_text, $comments_number ) {
        if ( 0 === $comments_number ) {
            $comments_number_text = __( 'No Comments Yet' );
        } elseif ( 1 === $comments_number ) {
            $comments_number_text = __( 'One Comment' );
        } else {
            $comments_number_text = $comments_number . ' ' . __( 'Awesome Comments' );
        }
    
        return $comments_number_text;
    }
    
    add_filter( 'comments_number', 'wpdocs_comments_number_filter', 10, 2 );

    By using apply_filters with the comments_number filter, you can easily customize the comments number text in WordPress. This technique allows you to tailor the comments display to meet your specific needs.

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