Taken from the articles referenced below:


"Properly strip all HTML tags including script and style."


"Strips all of the HTML in the content."


These functions appear to serve the exact same purpose. How are they different?


1 Answer 1


The wp_strip_all_tags() function will remove all HTML, including the content of script and style tags.

The PHP strip_tags() function largely does the same thing, except it won't eliminate the content of script and style tags. WP's wp_strip_all_tags() function uses this after eliminating the scripts and styles manually.

The wp_filter_nohtml_kses() function uses kses to remove all HTML. The main difference is the engine used for parsing the HTML. PHP's strip_tags() doesn't deal particularly well with broken or intentionally malformed HTML, because it doesn't perform any validation of the HTML. The kses engine attempts to handle malformed HTML in a better way, but it is also not a fully complete HTML parser. It is also much slower.

The wp_strip_all_tags() function is generally preferred. It's good enough for the majority of cases. The kses version is mostly included for completeness, but may be useful if you're dealing with particularly badly formed HTML.


Your Answer

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

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