WordPress has a baked in solution:
esc_html__( string $text, string $domain = 'default' )
You can use that to replace __()
and __x()
but the second one looks for contextual translations where you specify the context for the string being translated.
The codex for it is right here:
https://developer.wordpress.org/reference/functions/esc_html__/
Related Posts:
- What characters do I need to escape in XML documents?
- What characters must be escaped in HTML 5?
- How can I selectively escape percent (%) in Python strings?
- How do I escape a single quote in jQuery?
- Escape Character in SQL Server
- How to escape apostrophe (‘) in MySql?
- Should HTML output be passed through esc_html() AND wp_kses()?
- How to prevent escaping when saving HTML code in an option value?
- How to correctly escape query variables to be used in WP_Query
- esc_attr / esc_html / esc_url in echos
- When do I need to use esc_html()? [duplicate]
- what’s different between esc_attr, htmlspecialchars and htmlentities
- Allow all attributes in $allowedposttags tags
- When outputting a static string to the page, is it necessary to escape the output?
- How Flexible are the WordPress Coding Standards for PHPCS?
- why is esc_html() returning nothing given a string containing a high-bit character?
- Translate a Constant while appeasing WordPress PHPCS
- Using esc_url() on a url more than once
- Do I need to escape get_theme_mod(‘url’) / (‘mail’) with esc_url?
- How to allow   with wp_kses()?
- Using esc_attr_e
- Why esc_html_() is not used on every text that has a translation (on Twenty Twenty One)?
- Escaping crashes my output
- How to safely escape the title attribute
- How to safely escape data that contains HTML attributes
- Can wp_strip_all_tags be used as a substitute for esc_url, esc_attr & esc_html?
- Echoing a URL to a link
- wp_kses_post escaping doesn’t appear to work as described?
- file_get_contents | escaping doesnt show the page
- Help about Escaping
- How to keep specific tag from an html string?
- Escaping Issues
- Escaping and Special Characters (e.g. &)
- Escaping get_option( ‘time_format’ ) is nesserary?
- Uses for the ‘"’ entity in HTML
- How can I add ” character to a multi line string declaration in C#?
- Illegal Escape Character “\”
- Escape quotes in JavaScript
- How is \\n and \\\n interpreted by the expanded regular expression?
- Why shouldn’t `'` be used to escape single quotes?
- What does it mean to escape a string?
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- Escaping HTML strings with jQuery
- What’s the Use of ‘\r’ escape sequence?
- How do I escape ampersands in XML so they are rendered as entities in HTML?
- Unrecognized escape sequence for path string containing backslashes
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- Should I escape wordpress functions like the_title, the_excerpt, the_content
- What is the difference between esc_html filter vs attribute_escape filter?
- Sanitize and data validation with apply_filters() function
- How to print translation supported text with HTML URL
- How do translated, escaped strings (esc_attr) in Themes work?
- Escaping WP_Query tax_query when term has special character(s)
- Do I need to escape data passed to wp_localize_script()?
- how to escape wp_oembed_get for phpcs
- How to escape html code with html allowed
- esc before saving or before displaying does it matter?
- Updating a post without escaping ampersands?
- Prevent add_shortcode from escaping a tag
- Escape hexadecimals/rgba values
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- wp_specialchars and wp_specialchars_decode in a shortcode plugin
- Sanitizing comments or escaping comment_text()
- I am not understandinhg $wpdb->prepare correctly
- meta_query works locally but not on live server
- Prevent escaping javascript in visual editor
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Escape when echoed
- Quotes being escaped inside wp_editor when saved with wp_kses_post
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- Is it safe and good practice to use do_shortcode to escape?
- WP_Editor – Saving Value into Plugin Option – Stripping HTML
- Is it necessary to escape LIKE term in WP_User_Query?
- Post Content, Special Characters and Filters
- WordPress stripping away backslashes from HTML
- Updating post data on save (save_post vs wp_insert_post_data)
- What is the safe way to print tracking code / pixel code before tag or tag
- mysql_real_escape_string() vs. esc_sql() in WordPress
- How to escape html generate by a loop
- How to escape multiple attribute at once in WordPress?
- Add HTML to Term Description
- Trouble inserting string containing quotations marks with wpdb in save_post hook
- How to be escape Variables and options when echo?
- Is there any solution, ide/tool etc., for automatic escaping for WordPress?
- product description text displays above website when in shop page [closed]
- Proper way to use esc_html__ and esc_attr__ etc for escaping value for translation
- ACF Unexpected T_CONSTANT_ENCAPSED_STRING [closed]
- How to pass an array as attribute of shortcode to work properly shortcode parser?
- how can i send this to wp_head – escape problem
- How to correctly escape an echo
- how to unescape wordpress output
- How to use wp_filter_oembed_result?
- Escaping a WPDB Object in One Shot
- Render the metabox input values as HTML
- Where is escaped the shortcode?
- Code auto escaping is not working when using short codes
- Escaping a shortcode so it displays as-is [duplicate]
- problem with quotes on new post
- Using `esc_attr( get_block_wrapper_attributes() )`, results in `class=””wp-block-foo””`
- Escaping admin_url output being passed to js (esc_js vs esc_url)