esc_html_x() WordPress Function

The esc_html_x() function is used to escape HTMLspecial characters in a string. This function is similar to theesc_html() function, but with one additional argument. The first argument is the string to be escaped, and the second argument is the context. The context can be one of the following values: - 'single': Escapes HTMLspecial characters for use in a single quoted attribute value. - 'double': Escapes HTMLspecial characters for use in a double quoted attribute value. - 'entity': Escapes HTMLspecial characters for use in an HTML entity. - 'html': Escapes HTMLspecial characters for use in an HTML document. - 'js':Escapes HTMLspecial characters for use in a JavaScript context. - 'url': Escapes HTMLspecial characters for use in a URL.

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

Translate 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 value: 'default'


Top ↑

Return

(string) Translated text.


Top ↑

Source

File: wp-includes/l10n.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.