WordPress function that makes HTML safe to be sent via AJAX request

Depending on what kind of HTML you’re expecting, there are different tools you can use:

  • esc_html() escapes entire HTML blocks so you don’t end up with breaking characters in your JSON object literals.
  • esc_html_e() escapes (as above) and translates the string if you’re concerned about localization in that context.
  • wp_kses() will parse the HTML string and strip out any “evil” (explicitly disallowed) tags.

Leave a Comment