WordPress at Your Fingertips

_e() WP 1.2.0

Display translation of the text using a translation file.

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

To retrieve the translation for use in a variable, use a similar function __().

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

null. Nothing (null). Display the result.

Usage

<?php _e( $text, $domain ); ?>
$text(string) (required)
Text to translate.
$domain(string)
Translation file ID, specified during registration and connection of the translation file, see load_textdomain(). If not specified, the default WordPress translation file will be used.
Default: 'default'

Examples

#1 Translate the string

Example of using the function in a basic WordPress theme:

<?php _e( 'Comment:' ); ?>

If Russian localization file is used, it will display: "Комментарий:".

Since version 4.2, the WPLANG constant has been canceled and now the language is changed in the main site settings.

Before WordPress 4.2: Russian localization file means that the WPLANG constant is defined as ru_RU in wp-config.php file: define('WPLANG', 'ru_RU');. For such a translation, without specifying a $domain, the default wp-content/languages/ru_RU.mo file will be used.

#2 String translation with specifying translation domain

To translate a string from own translation file, we need to specify second parameter $domain. It bind translation string to translation file. $domain and the translation file are registered with the load_textdomain() function;

<?php _e( 'Comment: ', 'mydomain' ); ?>

#3 Make a string inside your plugin or theme translatable

<?php _e( 'Hello World', 'text_domain' ); ?>

Hello World and text_domain should always be directly passed as a string literal as shown above, not a string assigned to a variable.

This is incorrect:

<?php
$text_domain = 'text_domain';
$string = 'Hello World!';
_e( $string, $text_domain );
?>

#4 Display translation

There is similar function __(), which returns the result, but not display it. For Example the following strings are the same:

_e( 'this is some message', 'text_domain' );

// is same as
echo __( 'this is a some message', 'text_domain' );

Changelog

Since 1.2.0 Introduced.

Code of _e() WP 5.7.2

<?php
function _e( $text, $domain = 'default' ) {
	echo translate( $text, $domain );
}

From tag: localize (l10n i18n Internationalization localization)

More from category: Localization

No comments
    Log In