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

后端 未结 7 1188
遥遥无期
遥遥无期 2020-12-05 13:02

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 opt

相关标签:
7条回答
  • 2020-12-05 13:05

    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:

    • http://make.wordpress.org/docs/plugin-developer-handbook/plugin-components/internationalization/
    • http://codex.wordpress.org/I18n_for_WordPress_Developers
    0 讨论(0)
  • 2020-12-05 13:06

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

    0 讨论(0)
  • 2020-12-05 13:10

    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.

    0 讨论(0)
  • 2020-12-05 13:13

    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

    0 讨论(0)
  • 2020-12-05 13:17

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

    0 讨论(0)
  • 2020-12-05 13:26

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

    0 讨论(0)
提交回复
热议问题