WordPress at a glance

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.

Works based on: translate(), esc_html()

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

#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>

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

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

Code of esc html : wp-includes/l10n.php VER 5.1.1

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

Related Functions

From tag: localize (l10n i18n Internationalization localization)

More from category: Localization

No comments
    Hello, !     Log In . Register