What does the Wordpress “_e()” function do?

2019-01-23 10:16发布

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 wordpress
8条回答
可以哭但决不认输i
2楼-- · 2019-01-23 10:51

The _e() function display translated text.

_e( string $text, string $domain = 'default' )

You could found more information about at the Wordpress Documentation: _e() function

查看更多
Melony?
3楼-- · 2019-01-23 10:52

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()

查看更多
走好不送
4楼-- · 2019-01-23 10:57

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:

查看更多
太酷不给撩
5楼-- · 2019-01-23 10:58

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.

查看更多
劫难
6楼-- · 2019-01-23 11:03

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.

查看更多
祖国的老花朵
7楼-- · 2019-01-23 11:07

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

查看更多
登录 后发表回答