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

Translates string with gettext 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.


Top ↑

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'


Top ↑

Return

string Translated text.


Top ↑

Source

File: wp-includes/l10n.php. View all references

function esc_html_x( $text, $context, $domain = 'default' ) {
	return esc_html( translate_with_gettext_context( $text, $context, $domain ) );
}


Top ↑

Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Abdul Hadi

    The _x functions (like esc_html_x) are essentially the same as their _e counterparts, 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 asking 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.