wp_strip_all_tags()
Removes all HTML tags from passed content. Script/Style tags removed with their content.
This differs from strip_tags() because it removes the contents of the <script> and <style> tags. For example:
strip_tags( '<script>something</script>' ); // something wp_strip_all_tags( '<script>something</script>' ); // empty ''
Works based on strip_tags()
Use trim() to Strip whitespace from the beginning and end of a string.
Used By: wp_html_excerpt(), sanitize_text_field()
1 time — 0.000001 sec (speed of light) | 50000 times — 0.07 sec (speed of light) | PHP 7.4.8, WP 5.6.1
No Hooks.
Return
String
. The processed string.
Usage
wp_strip_all_tags( $string, $remove_breaks );
- $string(string) (required)
- String containing HTML tags
- $remove_breaks(true|false)
- Whether to remove left over line breaks and white space chars
Default: false
Examples
#1 Strip all HTML tags
Strips all HTML tags from the string, so it becomes super safe to display it.
$str = '<script>code</script> 11<br> 22 <strong>333</strong> '; $str = wp_strip_all_tags( $str, 0 ); // $str contains // '11 22 333'
Changelog
Since 2.9.0 | Introduced. |
wp_strip_all_tags() wp strip all tags code WP 6.1.1
function wp_strip_all_tags( $string, $remove_breaks = false ) { $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); $string = strip_tags( $string ); if ( $remove_breaks ) { $string = preg_replace( '/[\r\n\t ]+/', ' ', $string ); } return trim( $string ); }