wp-includes/l10n.php:306Translate a string and return it with __(): looks up $text in a text domain and gives back the translation, or the original text when none exists. It returns rather than prints, so use it wherever you need the localized string as a value; _e() is the echoing counterpart.
Retrieves the translation of $text.
$textstring$domainstringoptional'default'stringEvery example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Reach for __() when the translated text feeds into another function or gets concatenated before output.
$label = __( 'Read more', 'myplugin' );
printf(
'<a class="more-link" href="%s">%s</a>',
esc_url( get_permalink() ),
esc_html( $label )
);Always pass a literal string, never a variable: translation tools extract strings from source statically, so __( $message, 'myplugin' ) produces nothing translators can see. The domain must match the one your plugin or theme loads.
function __( $text, $domain = 'default' ) { return translate( $text, $domain );}Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.