__( string $text, string $domain = 'default' ): string
In this article
Retrieves the translation of $text.
Description
If there is no translation, or the text domain isn’t loaded, the original text is returned.
Parameters
$text
stringrequired- Text to translate.
$domain
stringoptional- Text domain. Unique identifier for retrieving translated strings.
Default'default'
.Default:
'default'
Return
string Translated text.Source
*/
function __( $text, $domain = 'default' ) {
return translate( $text, $domain );
Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |
User Contributed Notes
-
Skip to note 4 content You must log in to vote on the helpfulness of this note Vote results for this note: 10You must log in to vote on the helpfulness of this note -
Skip to note 5 content You must log in to vote on the helpfulness of this note Vote results for this note: 8You must log in to vote on the helpfulness of this noteWe have _e as well which do the same thing but and only difference between them is
_e echo directly whereas __ we need to echo them.For Example:
_e(‘this is some message’, ‘twentyfourteen’);
is same as
echo __(‘this is a some message’, ‘twentyfourteen’);
-
Skip to note 6 content You must log in to vote on the helpfulness of this note Vote results for this note: 7You must log in to vote on the helpfulness of this noteMake a string inside your plugin or theme translatable:
$translated = __( 'Hello World!', 'mytextdomain' );
‘mytextdomain’ needs to be a unique text domain used throughout your plugin/theme. This should always be directly passed as a string literal as shown above, not a string assigned to a variable or constant. E.g., this is incorrect:
$text_domain = 'mytextdomain'; $string = 'Hello World!'; $translated = __( $string, $text_domain );
This seems to work, but it will interfere in automatic parsing of your plugin/theme’s files for translation.
You must log in before being able to contribute a note or feedback.
For escaping text that contains links, use __() in combination with sprintf. Like this
This will prevent the links from being changed by translators.