What does the WordPress "_e()" function do?

PhpWordpress

Php Problem Overview


I have these all over my theme, and when if I delete them, there nothing happens to the theme. What does it do? Should I leave them in or are they unnecessary? I want to optimize my site to load faster, so this is why I'm asking.

Php Solutions


Solution 1 - Php

https://developer.wordpress.org/reference/functions/_e/

> In WordPress, strings in the php files are marked for translation to other languages, and localization using two “tags” which are actually functions. They are: > > __() > _e()

Solution 2 - Php

They are used for localization in WordPress themes. If you're only using one language for your theme, you don't need them.

Solution 3 - Php

These are for WordPress localization.

Here is their documentation: http://codex.wordpress.org/Function_Reference/_e

Also a few links on localization in general on WordPress to put the _e's in context:

Solution 4 - Php

It is a WordPress Function used for localization. See the WordPress Docs for localization.

With this function you can output/assign "hardcoded" strings within your theme/plugin/code that are translateable (with .mo / .po files or plugins like WPML String Translation).

The function __( 'My Text', 'my-text-domain' ); assigns a string "My Text" that is translateable. 'my-text-domain' is the text-doamin the string is referenced to. This function does not echo anything!

The function _e( 'My Text', 'my-text-domain' ); is almost the same but it echoes your string directly.

WordPress Offers several other functions for localization, take a look into the Codex (link on top of my answer).

Solution 5 - Php

Those are WordPress library function used on localization in Wordpress themes. Its recommended to use escapes function as much as possible in theme and plugins for safety.

>

() = Return the translated string

>e() = echo the translated string
>esc_html
_() = Escapes & return the translation string use in HTML output
>esc_html_e() = Escapes & echo the translation string use in HTML output
>esc_attr
() = Escapes & return the translation string use in an attribute
>esc_attr_e() = Escapes & echo the translation string use in an attribute

> >_n() = Retrieve the plural or single form based on the amount.

> >_x() = Retrieve translated string with gettext context
>_ex() = echo translated string with gettext context
>esc_attr_x() = Escapes & return translated string with gettext context use in an attribute
>esc_html_x() = Escapes & return translated string with gettext context use in HTML output

Solution 6 - Php

If you want echo the translated string, then you will be using _e and when you just want to have the translated string, then you will be using __.

Solution 7 - Php

Actually, from my experience, I find that _e() is a function. It is similar to:

<?php function _e($txt) { echo $txt; }

It seems to me that if you eliminate it, you run the risk of your text not even showing up. From the uses I have seen, though, it is comments to the WordPress user to remind them to add information to the area, like the footer, header, or whatever. So eliminating may only remove all the hints the theme has built in for you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdamView Question on Stackoverflow
Solution 1 - PhpaustinbvView Answer on Stackoverflow
Solution 2 - PhpGustav LarssonView Answer on Stackoverflow
Solution 3 - PhpRyan CView Answer on Stackoverflow
Solution 4 - PhpAdrian LambertzView Answer on Stackoverflow
Solution 5 - PhpIqbalBaryView Answer on Stackoverflow
Solution 6 - PhpvishalView Answer on Stackoverflow
Solution 7 - PhpGrafixGuyView Answer on Stackoverflow