Title: wp_kses_post
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_kses_post( string $data ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#wp--skip-link--target)

Sanitizes content for allowed HTML tags for post content.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#description)󠁿

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

This function expects unslashed data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#parameters)󠁿

 `$data`stringrequired

Post content to filter.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/kses.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/kses.php#L2502)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/kses.php#L2502-L2504)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_kses()](https://developer.wordpress.org/reference/functions/wp_kses/)`wp-includes/kses.php` |

Filters text content and strips out disallowed HTML.

  |

| Used by | Description | 
| [_block_bindings_term_data_get_value()](https://developer.wordpress.org/reference/functions/_block_bindings_term_data_get_value/)`wp-includes/block-bindings/term-data.php` |

Gets value for Term Data source.

  | 
| [wp_admin_notice()](https://developer.wordpress.org/reference/functions/wp_admin_notice/)`wp-includes/functions.php` |

Outputs an admin notice.

  | 
| [WP_Site_Health::get_test_page_cache()](https://developer.wordpress.org/reference/classes/wp_site_health/get_test_page_cache/)`wp-admin/includes/class-wp-site-health.php` |

Tests if a full page cache is available.

  | 
| [WP_Widget_Block::update()](https://developer.wordpress.org/reference/classes/wp_widget_block/update/)`wp-includes/widgets/class-wp-widget-block.php` |

Handles updating settings for the current Block widget instance.

  | 
| [WP_REST_Pattern_Directory_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php` |

Prepare a raw block pattern before it gets output in a REST API response.

  | 
| [WP_Widget_Custom_HTML::update()](https://developer.wordpress.org/reference/classes/wp_widget_custom_html/update/)`wp-includes/widgets/class-wp-widget-custom-html.php` |

Handles updating settings for the current Custom HTML widget instance.

  | 
| [install_plugin_information()](https://developer.wordpress.org/reference/functions/install_plugin_information/)`wp-admin/includes/plugin-install.php` |

Displays plugin information in dialog box form.

  | 
| [do_settings_sections()](https://developer.wordpress.org/reference/functions/do_settings_sections/)`wp-admin/includes/template.php` |

Prints out all settings sections added to a particular settings page.

  | 
| [wp_add_id3_tag_data()](https://developer.wordpress.org/reference/functions/wp_add_id3_tag_data/)`wp-admin/includes/media.php` |

Parses ID3v2, ID3v1, and getID3 comments to extract usable data.

  | 
| [WP_Widget_Text::update()](https://developer.wordpress.org/reference/classes/wp_widget_text/update/)`wp-includes/widgets/class-wp-widget-text.php` |

Handles updating settings for the current Text widget instance.

  | 
| [WP_SimplePie_Sanitize_KSES::sanitize()](https://developer.wordpress.org/reference/classes/wp_simplepie_sanitize_kses/sanitize/)`wp-includes/class-wp-simplepie-sanitize-kses.php` |

WordPress SimplePie sanitization using KSES.

  | 
| [WP_Customize_Widgets::sanitize_widget_instance()](https://developer.wordpress.org/reference/classes/wp_customize_widgets/sanitize_widget_instance/)`wp-includes/class-wp-customize-widgets.php` |

Sanitizes a widget instance.

  |

[Show 7 more](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_kses_post/?output_format=md#comment-content-3376)
 2.   [Pitabas](https://profiles.wordpress.org/pitabas106/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/wp_kses_post/#comment-3376)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_kses_post%2F%23comment-3376)
    Vote results for this note: -5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_kses_post%2F%23comment-3376)
 4. **Display Admin notice**
 5. The following example of basic usage of the `wp_kses_post()` function. We can use
    it to print the message in the admin screen.
 6.     ```php
        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 );
        }
        ```
    
 7.  * This is another example for a plugin when allow HTML in a textarea field. ` 
       public function field_message() { $opts = $this->get_options(); ?> <textarea
       name="[message]" rows="3" class="large-text"> <?php } private function render_bar(
       $opts ) { $message = apply_filters( 'sabw_alert_message', $opts['message'], 
       $opts ); echo ''; echo wp_kses_post( $message ); echo ''; do_action( 'sabw_rendered_alert',
       $opts ); } `
     * [yourallyagency](https://profiles.wordpress.org/yourallyagency/) [11 months ago](https://developer.wordpress.org/reference/functions/wp_kses_post/#comment-7412)
 8.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_kses_post%2F%3Freplytocom%3D3376%23feedback-editor-3376)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_kses_post%2F)
before being able to contribute a note or feedback.