Can anyone explain why I would use __()
over esc_html_e()
相关问题
- Display product ACF field value in Woocommerce tra
- Adding a custom button after add to cart button in
- How to add a “active” class to a carousel first el
- Setting custom order statuses as valid for payment
- change the font size in tag cloud
相关文章
- wordpress新增页面如何个性化设置
- select query in wordpress
- Get WooCommerce featured products in a WP_Query
- Woocommerce update shipping methods in checkout vi
- Change order status just after payment in WooComme
- Publishing or uploading failed. Error message: “Th
- Facebook Login With WP JWT Auth
- Wordpress development process
__()
is primarily for simple text that doesn't contain markup that needs to be escaped. It differs from_e()
in that the former returns the translated text while the latter echoes the translated text.esc_html_e()
andesc_html__()
are similar, but they are used for strings that do contain markup. They each escape the provided string, and then call on their corresponding_e()
or__()
counterparts depending on which one you use.Escaping HTML is necessary if you're accepting strings provided from user input. XSS attacks are probably the most common types of attacks on sites that accept user input and render it on the page. An attacker can easily provide
<script>
tags and execute arbitrary Javascript on your page if the input is not properly cleaned or escaped.Just like the docs state,
esc_html_e()
retrieves a translated string, escapes it, and echoes the result.__()
returns a translated string. The source for each of these functions makes this crystal clear: