I'm trying to let the admin store a js code with one of the plugins I developed. For some reason for(i = 0; i < 5; i++) stores as for(i = 0; i &lt; 5; i++). I'm using sanitize_textarea_field to store the field from a textarea. Also, I've tried esc_js and json_encode, which did not worked for me also.

How can I fix this?


1 Answer 1


If you search WordPress core for &lt; or &gt; you will find the function _wp_specialchars in /wp-includes/formatting.php

Then if you search for _wp_specialchars you will see it is used in esc_js (as well as esc_html and esc_attr) so do not use esc_js, escaping is mostly for output anyway.

Further search results show that in /wp-includes/default-filters.php that _wp_specialchars is added to multiple filters with a priority of 30. So what you would need to do is find out which filter is being applied to your text area value before saving, so that then you can do this before saving:

remove_filter('NAME_OF_FILTER_HOOK', '_wp_specialchars', 30);

It is hard to be more specific than that without the actual code used, but this should give you enough clues to find what you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.