__( string $text, string $domain = 'default' ): string
- Since
- 2.1.0
- Source
wp-includes/l10n.php:305
Translate 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.
Description
If there is no translation, or the text domain isn't loaded, the original text is returned.
Compatibility
- WordPress
- since 2.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$textstring- Text to translate.
$domainstringoptional- Text domain. Unique identifier for retrieving translated strings.
Default 'default'.Default:'default'
Return value
string- Translated text.
Code examples
Every 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.
Use a translated string as a value
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.
Performance profile
How much work a call to __() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 7
- Plugin surface
- None
- Called by
- 50
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 7.
Nothing here hands control to plugin code.
50 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below __()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost __() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7 | translate() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 7 instructions, 7 executed per call, 0 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- translate()Retrieves the translation of $text.
Used by · 50
- AtomParser::parse()
- Bulk_Plugin_Upgrader_Skin::add_strings()Sets up the strings used in the update process.
- Bulk_Plugin_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- Bulk_Theme_Upgrader_Skin::add_strings()Sets up the strings used in the update process.
- Bulk_Theme_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- Bulk_Upgrader_Skin::add_strings()Sets up the strings used in the update process.
- Bulk_Upgrader_Skin::after()Performs an action following a bulk update.
- Core_Upgrader::upgrade()Upgrades WordPress core.
- Core_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Custom_Background::admin_load()Sets up the enqueue for the CSS & JavaScript files.
- Custom_Background::admin_page()Displays the custom background page.
- Custom_Background::handle_upload()Handles an Image upload for the background image.
Show all 50
- Custom_Background::wp_set_background_image()
- Custom_Image_Header::admin_page()Displays the page based on the current step.
- Custom_Image_Header::ajax_header_crop()Gets attachment uploaded by Media Manager, crops it, then saves it as a new object. Returns JSON-encoded object details.
- Custom_Image_Header::help()Adds contextual help.
- Custom_Image_Header::step_1()Displays first step of custom header image page.
- Custom_Image_Header::step_2()Displays second step of custom header image page.
- Custom_Image_Header::step_2_manage_upload()Uploads the file to be cropped in the second step.
- Custom_Image_Header::step_3()Displays third step of custom header image page.
- Featured_Content::customize_register()Add settings to the Customizer.
- File_Upload_Upgrader::__construct()Construct the upgrader for a form.
- IXR_Message::parse()
- Language_Pack_Upgrader::check_package()Checks that the package source contains .mo and .po files.
- Language_Pack_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Language_Pack_Upgrader_Skin::__construct()Constructor.
- Language_Pack_Upgrader_Skin::before()Performs an action before a language pack update.
- Language_Pack_Upgrader_Skin::bulk_footer()Displays the footer following the bulk update process.
- Plugin_Installer_Skin::after()Performs an action following a plugin install.
- Plugin_Installer_Skin::do_overwrite()Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.
- Plugin_Upgrader::bulk_upgrade()Upgrades several plugins at once.
- Plugin_Upgrader::check_package()Checks that the source package contains a valid plugin.
- Plugin_Upgrader::install_strings()Initializes the installation strings.
- Plugin_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Plugin_Upgrader_Skin::__construct()Constructor.
- Plugin_Upgrader_Skin::after()Performs an action following a single plugin update.
- Theme_Installer_Skin::after()Performs an action following a single theme install.
- Theme_Installer_Skin::do_overwrite()Checks if the theme can be overwritten and outputs the HTML for overwriting a theme on upload.
- Theme_Upgrader::bulk_upgrade()Upgrades several themes at once.
- Theme_Upgrader::check_package()Checks that the package source contains a valid theme.
- Theme_Upgrader::install_strings()Initializes the installation strings.
- Theme_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Theme_Upgrader_Skin::__construct()Constructor.
- Theme_Upgrader_Skin::after()Performs an action following a single theme update.
- TwentyNineteen_Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- TwentyTwenty_Customize::register()Register customizer options.
- TwentyTwenty_Walker_Comment::html5_comment()Outputs a comment in the HTML5 format.
- TwentyTwenty_Walker_Page::start_el()Outputs the beginning of the current element in the tree.
- Twenty_Eleven_Ephemera_Widget::__construct()PHP5 constructor.
- Twenty_Eleven_Ephemera_Widget::widget()Outputs the HTML for this widget.
Source code
function __( $text, $domain = 'default' ) { return translate( $text, $domain );}Changelog
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.