How to escape single and plural i18n text strings?

esc_html_e() and esc_attr_e() are merely wrapper functions for _ to save a little bit of typing and help with readability. You’re right, there isn’t one for _n, so you’ll just need to do the “wrapping” yourself:

printf(
    esc_attr(
        _n(
            '%s item',
            '%s items',
            $count,
            'textdomain'
        )
    ),
    number_format_i18n( $count )
);

Leave a Comment