WordPress“_e()”的作用是什么?功能做什么?
我的主题中到处都是这些,当我删除它们时,主题不会发生任何变化。它有什么作用?我应该把它们留在里面还是没有必要?我想优化我的网站以加载得更快,所以这就是我问的原因。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
https://developer.wordpress.org/reference/functions/_e/
https://developer.wordpress.org/reference/functions/_e/
它们用于 WordPress 主题的本地化。如果您的主题仅使用一种语言,则不需要它们。
They are used for localization in WordPress themes. If you're only using one language for your theme, you don't need them.
这些用于 WordPress 本地化。
这是他们的文档: http://codex.wordpress.org/Function_Reference/_e
WordPress 上一般本地化的几个链接将 _e 放在上下文中:
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:
这是一个用于本地化的 WordPress 函数。
请参阅 WordPress 文档进行本地化。
使用此功能,您可以在主题中输出/分配“硬编码”字符串/可翻译的插件/代码(带有 .mo / .po 文件 或插件(例如 WPML 字符串翻译)。
函数
__( 'My Text', 'my-text-domain' );
分配一个可翻译的字符串“My Text”。 'my-text-domain' 是字符串引用的文本域。此函数不回显任何内容!函数
_e( 'My Text', 'my-text-domain' );
几乎相同但它直接回显您的字符串。WordPress 提供了其他几个本地化功能,请查看 Codex(我的答案顶部的链接)。
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).
这些是用于 WordPress 主题本地化的 WordPress 库函数。为了安全,建议主题和插件中尽可能使用转义功能。
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.
如果您想回显翻译后的字符串,那么您将使用 _e 和
当您只想获得翻译后的字符串时,您将使用 __。
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 __.
实际上,根据我的经验,我发现 _e() 是一个函数。它类似于:
看来,如果你消除它,你就会面临文本甚至不显示的风险。不过,从我所看到的用途来看,它是对 WordPress 用户的注释,提醒他们向该区域添加信息,例如页脚、页眉或其他内容。因此,消除可能只会删除主题为您内置的所有提示。
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.