_n

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

WordPress Version: 6.2

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 * @since 5.5.0 Introduced `ngettext-{$domain}` filter.
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param int    $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
    /**
     * Filters the singular or plural form of a string for a domain.
     *
     * The dynamic portion of the hook name, `$domain`, refers to the text domain.
     *
     * @since 5.5.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param int    $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters("ngettext_{$domain}", $translation, $single, $plural, $number, $domain);
    return $translation;
}

WordPress Version: 6.1

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 * @since 5.5.0 Introduced ngettext-{$domain} filter.
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param int    $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
    /**
     * Filters the singular or plural form of a string for a domain.
     *
     * The dynamic portion of the hook name, `$domain`, refers to the text domain.
     *
     * @since 5.5.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param int    $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters("ngettext_{$domain}", $translation, $single, $plural, $number, $domain);
    return $translation;
}

WordPress Version: 5.9

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 * @since 5.5.0 Introduced ngettext-{$domain} filter.
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
    /**
     * Filters the singular or plural form of a string for a domain.
     *
     * The dynamic portion of the hook name, `$domain`, refers to the text domain.
     *
     * @since 5.5.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters("ngettext_{$domain}", $translation, $single, $plural, $number, $domain);
    return $translation;
}

WordPress Version: 5.5

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 * @since 5.5.0 Introduced ngettext-{$domain} filter.
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
    /**
     * Filters the singular or plural form of a string for a domain.
     *
     * The dynamic portion of the hook, `$domain`, refers to the text domain.
     *
     * @since 5.5.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    $translation = apply_filters("ngettext_{$domain}", $translation, $single, $plural, $number, $domain);
    return $translation;
}

WordPress Version: 4.7

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    return apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
}

WordPress Version: 4.6

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     $people = sprintf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filters the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    return apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
}

WordPress Version: 4.4

/**
 * Translates and retrieves the singular or plural form based on the supplied number.
 *
 * Used when you want to use the appropriate form of a string based on whether a
 * number is singular or plural.
 *
 * Example:
 *
 *     $people = sprintf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
 *
 * @since 2.8.0
 *
 * @param string $single The text to be used if the number is singular.
 * @param string $plural The text to be used if the number is plural.
 * @param int    $number The number to compare against to use either the singular or plural form.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 *                       Default 'default'.
 * @return string The translated singular or plural form.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filter the singular or plural form of a string.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text to be used if the number is singular.
     * @param string $plural      The text to be used if the number is plural.
     * @param string $number      The number to compare against to use either the singular or plural form.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    return apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
}

WordPress Version: 3.7

/**
 * Retrieve the plural or single form based on the supplied amount.
 *
 * If the text domain is not set in the $l10n list, then a comparison will be made
 * and either $plural or $single parameters returned.
 *
 * If the text domain does exist, then the parameters $single, $plural, and $number
 * will first be passed to the text domain's ngettext method. Then it will be passed
 * to the 'ngettext' filter hook along with the same parameters. The expected
 * type will be a string.
 *
 * @since 2.8.0
 *
 * @param string $single The text that will be used if $number is 1.
 * @param string $plural The text that will be used if $number is not 1.
 * @param int    $number The number to compare against to use either $single or $plural.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 * @return string Either $single or $plural translated text.
 */
function _n($single, $plural, $number, $domain = 'default')
{
    $translations = get_translations_for_domain($domain);
    $translation = $translations->translate_plural($single, $plural, $number);
    /**
     * Filter text with its translation when plural option is available.
     *
     * @since 2.2.0
     *
     * @param string $translation Translated text.
     * @param string $single      The text that will be used if $number is 1.
     * @param string $plural      The text that will be used if $number is not 1.
     * @param string $number      The number to compare against to use either $single or $plural.
     * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
     */
    return apply_filters('ngettext', $translation, $single, $plural, $number, $domain);
}