wp_kses_post( string $data ): string

Sanitizes content for allowed HTML tags for post content.

Description

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

This function expects unslashed data.

Parameters

$datastringrequired
Post content to filter.

Return

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

Source

function wp_kses_post( $data ) {
	return wp_kses( $data, 'post' );
}

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Display Admin notice

    The following example of basic usage of the wp_kses_post() function. We can use it to print the message in the admin screen.

    if ( ! version_compare( PHP_VERSION, '5.6', '>=' ) ) {
    	add_action( 'admin_notices', 'wpdocs_fail_php_version' );
    } 
    
    /**
     * Admin notice for minimum PHP version.
     *
     * Warning when the site doesn't have the minimum required PHP version.
     *
     * @since 1.0.0
     *
     * @return void
     */
    function wpdocs_fail_php_version() {
    
    	if ( isset( $_GET['activate'] ) ) {
    		unset( $_GET['activate'] );
    	}
    
    	/* translators: %s: PHP version */
    	$message      = sprintf( __( '<strong>My Custom Plugin</strong> requires PHP version %s+, plugin is currently NOT RUNNING.', 'wpdocs-text-domain' ), '5.6' );
    	$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
    	echo wp_kses_post( $html_message );
    }

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