php WordPress“_e()”函数有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5775135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:27:09  来源:igfitidea点击:

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

phpwordpress

提问by Adam

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.

我的主题里都有这些,如果我删除它们,主题就没有任何反应。它有什么作用?我应该把它们留在里面还是它们是不必要的?我想优化我的网站以加快加载速度,所以这就是我问的原因。

回答by austinbv

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

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

在 WordPress 中,php 文件中的字符串被标记为翻译成其他语言,并使用两个实际上是函数的“标签”进行本地化。他们是:

__() _e()

回答by Gustav Larsson

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

它们用于 WordPress 主题的本地化。如果您的主题只使用一种语言,则不需要它们。

回答by Ryan C

These are for WordPress localization.

这些用于 WordPress 本地化。

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

这是他们的文档:http: //codex.wordpress.org/Function_Reference/_e

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

还有一些关于 WordPress 本地化的链接,用于将 _e 置于上下文中:

回答by Adrian Lambertz

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

它是用于本地化的 WordPress 功能。 有关本地化,请参阅 WordPress 文档。

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

使用此功能,您可以在主题/插件/代码中输出/分配可翻译的“硬编码”字符串(使用.mo / .po 文件或插件,如 WPML 字符串翻译)。

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!

该函数__( 'My Text', 'my-text-domain' );分配一个可翻译的字符串“我的文本”。'my-text-domain' 是字符串所引用的文本域。此功能不回显任何内容

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

该功能_e( 'My Text', 'my-text-domain' );几乎相同,但它直接回显您的字符串

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

WordPress 提供其他几种本地化功能,请查看 Codex(链接位于我的答案顶部)。

回答by IqbalBary

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.

这些是用于 Wordpress 主题本地化的 WordPress 库函数。为了安全起见,建议在主题和插件中尽可能使用转义功能。

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

__()= 返回翻译后的字符串
_e()= 回显翻译后的字符串
esc_html__()= Escapes & 返回 HTML 输出中使用的翻译字符串
esc_html_e()= Escapes & 回显 HTML 输出中使用的翻译字符串
esc_attr__()= Escapes &返回属性中使用的翻译字符串
esc_attr_e()= Escapes & 回显属性中使用的翻译字符串

_n()= 根据数量检索复数形式或单一形式。

_x()= 使用 gettext 上下文检索翻译后的字符串
_ex()= 使用 gettext 上下文回显翻译后的字符串
esc_attr_x()= 转义并返回在属性
esc_html_x()中使用 gettext 上下文的已翻译字符串 = 转义并返回在 HTML 输出中使用 gettext 上下文的已翻译字符串

回答by GrafixGuy

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

实际上,根据我的经验,我发现 _e() 是一个函数。它类似于:

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

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

在我看来,如果你消除它,你的文字甚至不显示的风险。但是,从我所看到的用途来看,它是对 WordPress 用户的评论,以提醒他们向该区域添加信息,例如页脚、页眉或其他任何内容。因此,消除可能只会删除主题为您内置的所有提示。