I have a textarea inside a custom widget that needs to hold some html tags. I've noticed that if I use the esc_html or esc_attr or strip_tags to take the things secure, I will lost all the html I use. How I can keep the html tags in place, I just need to add an <i> tag and <p> or <h>, <a> tags. Any suggestion?

1 Answer 1


Use wp_kses_post instead! It will keep all the tags allowed in a post, you can also use wp_kses and provide a list of tags and attributes

  • Thank you! I will implement it inside my widget code.
    – sialfa
    Dec 20, 2019 at 12:20
  • Just a question, with wp_kses, can I pass only the tags I want to allow, or I need to specify an array for the attributes for each tag?
    – sialfa
    Dec 20, 2019 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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