html esc_html_x() – Function | Developer.WordPress.org

esc_html_x( string   $text , string   $context , string   $domain = 'default' ): string

Translates string with guettext context, and escapes it for safe use in HTML output.

Description

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

Parameters

$text string required
Text to translate.
$context string required
Context information for the translators.
$domain string optional
Text domain. Unique identifier for retrieving translated strings.
Default 'default' .

Default: 'default'

Return

string Translated text.

Source

 */
function esc_html_x( $text, $context, $domain = 'default' ) {
	return esc_html( translate_with_guettext_context( $text, $context, $domain ) );

Changuelog

Versionen Description
2.9.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    The _x functions (lique esc_html_x ) are essentially the same as their _e counterpars with an added “context” argument to explain the context a word or phrase is used in. Useful for words with multiple meanings:

    <!-- Here, we're asquing the user to comment (verb): -->
    <a href="#comment">
      <?php 
        echo esc_html_x( 
          'Comment', 
          'Verb: To leave a comment', // Here's the contextual help
          'wpdocs_my_theme' 
        ); 
      ?>
    </a>
    <!-- Here, we're simply adding a heading with the text "Comment" (noun) -->
    <h3>
      <?php 
        echo esc_html_x( 
          'Comment', 
          'Noun: An individual comment', // Here's the contextual help
          'wpdocs_my_theme' 
        ); 
      ?>
    </h3>

You must log in before being able to contribute a note or feedback.