wp_strip_all_tags( string $string, bool $remove_breaks = false )

Properly strip all HTML tags including script and style

Description Description

This differs from strip_tags() because it removes the contents of the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' ) will return ‘something’. wp_strip_all_tags will return ”

Parameters Parameters


(string) (Required) String containing HTML tags


(bool) (Optional) Whether to remove left over line breaks and white space chars

Default value: false

Top ↑

Return Return

(string) The processed string.

Top ↑

Source Source

File: wp-includes/formatting.php

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 );

Top ↑

Changelog Changelog

Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.