__( string $text, string $domain = 'default' ): string

Retrieves the translation of $text.

Description

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

Parameters

$textstringrequired
Text to translate.
$domainstringoptional
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

VersionDescription
2.1.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    For escaping text that contains links, use __() in combination with sprintf. Like this

    sprintf( __( 'You can visit the page by clicking <a href="%s">here</a>.', 'text_domain' ), 
    			'http://example.com'
    		);

    This will prevent the links from being changed by translators.

  2. Skip to note 6 content

    Make 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.