esc_html_e()
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.
Uses: esc_html(), translate()
No Hooks.
Return
null
. Nothing (null).
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 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' );
#2 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>
Changelog
Since 2.8.0 | Introduced. |
esc_html_e() esc html e code WP 6.5.2
function esc_html_e( $text, $domain = 'default' ) { echo esc_html( translate( $text, $domain ) ); }