get_comments_number_text

The timeline below displays how wordpress function get_comments_number_text has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Displays the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
 *
 * @param string      $zero Optional. Text for no comments. Default false.
 * @param string      $one  Optional. Text for one comment. Default false.
 * @param string      $more Optional. Text for more than one comment. Default false.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
 * @return string Language string for the number of comments a post has.
 */
function get_comments_number_text($zero = false, $one = false, $more = false, $post = 0)
{
    $comments_number = get_comments_number($post);
    if ($comments_number > 1) {
        if (false === $more) {
            $comments_number_text = sprintf(
                /* translators: %s: Number of comments. */
                _n('%s Comment', '%s Comments', $comments_number),
                number_format_i18n($comments_number)
            );
        } else {
            // % Comments
            /*
             * translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Remove HTML entities.
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form.
                if ($text && !preg_match('/[0-9]+/', $text) && str_contains($more, '%')) {
                    /* translators: %s: Number of comments. */
                    $new_text = _n('%s Comment', '%s Comments', $comments_number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (!str_contains($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $comments_number_text = str_replace('%', number_format_i18n($comments_number), $more);
        }
    } elseif (0 == $comments_number) {
        $comments_number_text = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // Must be one.
        $comments_number_text = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $comments_number_text A translatable string formatted based on whether the count
     *                                     is equal to 0, 1, or 1+.
     * @param int    $comments_number      The number of post comments.
     */
    return apply_filters('comments_number', $comments_number_text, $comments_number);
}

WordPress Version: 6.2

/**
 * Displays the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
 *
 * @param string      $zero Optional. Text for no comments. Default false.
 * @param string      $one  Optional. Text for one comment. Default false.
 * @param string      $more Optional. Text for more than one comment. Default false.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
 * @return string Language string for the number of comments a post has.
 */
function get_comments_number_text($zero = false, $one = false, $more = false, $post = 0)
{
    $number = get_comments_number($post);
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: Number of comments. */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            /*
             * translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Remove HTML entities.
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form.
                if ($text && !preg_match('/[0-9]+/', $text) && false !== strpos($more, '%')) {
                    /* translators: %s: Number of comments. */
                    $new_text = _n('%s Comment', '%s Comments', $number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (false === strpos($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif (0 == $number) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // Must be one.
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 6.1

/**
 * Displays the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
 *
 * @param string      $zero Optional. Text for no comments. Default false.
 * @param string      $one  Optional. Text for one comment. Default false.
 * @param string      $more Optional. Text for more than one comment. Default false.
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
 * @return string Language string for the number of comments a post has.
 */
function get_comments_number_text($zero = false, $one = false, $more = false, $post = 0)
{
    $number = get_comments_number($post);
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: Number of comments. */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            /*
             * translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Kill entities.
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form.
                if ($text && !preg_match('/[0-9]+/', $text) && false !== strpos($more, '%')) {
                    /* translators: %s: Number of comments. */
                    $new_text = _n('%s Comment', '%s Comments', $number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (false === strpos($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif (0 == $number) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // Must be one.
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 5.4

/**
 * Displays the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop.
 *
 * @param string      $zero    Optional. Text for no comments. Default false.
 * @param string      $one     Optional. Text for one comment. Default false.
 * @param string      $more    Optional. Text for more than one comment. Default false.
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
 * @return string Language string for the number of comments a post has.
 */
function get_comments_number_text($zero = false, $one = false, $more = false, $post_id = 0)
{
    $number = get_comments_number($post_id);
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: Number of comments. */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            /*
             * translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Kill entities.
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form.
                if ($text && !preg_match('/[0-9]+/', $text) && false !== strpos($more, '%')) {
                    /* translators: %s: Number of comments. */
                    $new_text = _n('%s Comment', '%s Comments', $number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (false === strpos($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif (0 == $number) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // Must be one.
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 5.3

/**
 * Display the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 *
 * @param string $zero Optional. Text for no comments. Default false.
 * @param string $one  Optional. Text for one comment. Default false.
 * @param string $more Optional. Text for more than one comment. Default false.
 */
function get_comments_number_text($zero = false, $one = false, $more = false)
{
    $number = get_comments_number();
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: Number of comments. */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            /*
             * translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Kill entities
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form
                if ($text && !preg_match('/[0-9]+/', $text) && false !== strpos($more, '%')) {
                    /* translators: %s: Number of comments. */
                    $new_text = _n('%s Comment', '%s Comments', $number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (false === strpos($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif ($number == 0) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // must be one
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 4.6

/**
 * Display the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 *
 * @param string $zero Optional. Text for no comments. Default false.
 * @param string $one  Optional. Text for one comment. Default false.
 * @param string $more Optional. Text for more than one comment. Default false.
 */
function get_comments_number_text($zero = false, $one = false, $more = false)
{
    $number = get_comments_number();
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: number of comments */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            /* translators: If comment number in your language requires declension,
             * translate this to 'on'. Do not translate into your own language.
             */
            if ('on' === _x('off', 'Comment number declension: on or off')) {
                $text = preg_replace('#<span class="screen-reader-text">.+?</span>#', '', $more);
                $text = preg_replace('/&.+?;/', '', $text);
                // Kill entities
                $text = trim(strip_tags($text), '% ');
                // Replace '% Comments' with a proper plural form
                if ($text && !preg_match('/[0-9]+/', $text) && false !== strpos($more, '%')) {
                    /* translators: %s: number of comments */
                    $new_text = _n('%s Comment', '%s Comments', $number);
                    $new_text = trim(sprintf($new_text, ''));
                    $more = str_replace($text, $new_text, $more);
                    if (false === strpos($more, '%')) {
                        $more = '% ' . $more;
                    }
                }
            }
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif ($number == 0) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // must be one
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filters the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 4.4

/**
 * Display the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 *
 * @param string $zero Optional. Text for no comments. Default false.
 * @param string $one  Optional. Text for one comment. Default false.
 * @param string $more Optional. Text for more than one comment. Default false.
 */
function get_comments_number_text($zero = false, $one = false, $more = false)
{
    $number = get_comments_number();
    if ($number > 1) {
        if (false === $more) {
            /* translators: %s: number of comments */
            $output = sprintf(_n('%s Comment', '%s Comments', $number), number_format_i18n($number));
        } else {
            // % Comments
            $output = str_replace('%', number_format_i18n($number), $more);
        }
    } elseif ($number == 0) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // must be one
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filter the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}

WordPress Version: 4.0

/**
 * Display the language string for the number of comments the current post has.
 *
 * @since 4.0.0
 *
 * @param string $zero Optional. Text for no comments. Default false.
 * @param string $one  Optional. Text for one comment. Default false.
 * @param string $more Optional. Text for more than one comment. Default false.
 */
function get_comments_number_text($zero = false, $one = false, $more = false)
{
    $number = get_comments_number();
    if ($number > 1) {
        $output = str_replace('%', number_format_i18n($number), (false === $more) ? __('% Comments') : $more);
    } elseif ($number == 0) {
        $output = (false === $zero) ? __('No Comments') : $zero;
    } else {
        // must be one
        $output = (false === $one) ? __('1 Comment') : $one;
    }
    /**
     * Filter the comments count for display.
     *
     * @since 1.5.0
     *
     * @see _n()
     *
     * @param string $output A translatable string formatted based on whether the count
     *                       is equal to 0, 1, or 1+.
     * @param int    $number The number of post comments.
     */
    return apply_filters('comments_number', $output, $number);
}