wp_kses_post( string $data )

Sanitizes content for allowed HTML tags for post content.


Description Description

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

This function expects unslashed data.


Top ↑

Parameters Parameters

$data

(string) (Required) Post content to filter.


Top ↑

Return Return

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



Top ↑

Source Source

File: wp-includes/kses.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Pitabas

    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.