esc_html__()WP 2.8.0

Translates specified string and escapes it for safe use in HTML output.

If there is no translation, or the text domain isn't loaded, the original text is escaped and returned.

No Hooks.

Return

String. Translated and escaped string for output in HTML.

Usage

esc_html__( $text, $domain );
$text(string) (required)
Text to translate.
$domain(string)
Text domain. Unique identifier for retrieving translated strings.
Default: 'default'

Examples

0

#1 Output in the tag

If the translation has HTML tags or characters that need to be shown as it is, for example in <textarea> tag, then it is smart to translate it with this function:

<textarea>
	<?php echo esc_html__('Any text with <span>HTML.</span>', 'textdomain'); ?>
</textarea>
0

#2 Same as in the first example but in a different way

<?php echo esc_html( __('Any text with <span>HTML.</span>', 'textdomain') );

Changelog

Since 2.8.0 Introduced.

esc_html__() code WP 6.5.2

function esc_html__( $text, $domain = 'default' ) {
	return esc_html( translate( $text, $domain ) );
}