WordPress at Your Fingertips

esc_html_e() WP 2.8.0

Translates specified string and escape/clears it for showing on screen - replaces special characters in it with HTML entities.

Displays text that can be used in HTML as HTML code.

use esc_html__() for get the same sting without printing it.

No Hooks.

Return

null. Nothing.

Usage

esc_html_e( $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 such a string with this function:

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

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

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

// Or so
echo esc_html__( 'Any text with <div>HTML.</div>', 'kama' );

Code of esc_html_e() WP 5.8.3

function esc_html_e( $text, $domain = 'default' ) {
	echo esc_html( translate( $text, $domain ) );
}

esc_ (clean validate sanitize)

localize (l10n i18n Internationalization localization)

Localization

No comments
    Log In