wp_filter_post_kses()WP 2.0.0

Sanitize content for allowed HTML tags for post content.

Post content refers to the page contents of the 'post' type and not $_POST data from forms.

This function expects slashed data.

Uses: wp_kses()

No Hooks.


String. Filtered post content with allowed HTML tags and attributes intact.


wp_filter_post_kses( $data );
$data(string) (required)
Post content to filter, expected to be escaped with slashes.



#1 Demo

This is how the function will work if you are an administrator:

$data = '<p data-url="foo">Auto.</p>
<div>Check div</div>
<script>check script</script>
<em>Example. Source numbers:  66, 43.</em>

$data = wp_filter_post_kses( $data );

echo htmlspecialchars( $data );

It will:
<div>Check div</div>
Checking the script
<em>Example. Source numbers:  66, 43.</em>


Since 2.0.0 Introduced.

wp_filter_post_kses() code WP 6.5.3

function wp_filter_post_kses( $data ) {
	return addslashes( wp_kses( stripslashes( $data ), 'post' ) );