WordPress“_e()”的作用是什么?功能做什么?

发布于 2024-11-02 21:43:29 字数 88 浏览 1 评论 0原文

我的主题中到处都是这些,当我删除它们时,主题不会发生任何变化。它有什么作用?我应该把它们留在里面还是没有必要?我想优化我的网站以加载得更快,所以这就是我问的原因。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

握住我的手 2024-11-09 21:43:29

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

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

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

二智少女猫性小仙女 2024-11-09 21:43:29

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

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

落花随流水 2024-11-09 21:43:29

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:

流年已逝 2024-11-09 21:43:29

这是一个用于本地化的 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).

2024-11-09 21:43:29

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

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

_n() = 根据金额检索复数或单数形式。

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

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

温柔戏命师 2024-11-09 21:43:29

如果您想回显翻译后的字符串,那么您将使用 _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 __.

痴梦一场 2024-11-09 21:43:29

实际上,根据我的经验,我发现 _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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文