WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp kses

Contents

Description

This function makes sure that only the allowed HTML element names, attribute names and attribute values plus only sane HTML entities will occur in $string. You have to remove any slashes from PHP's magic quotes before you call this function.

Usage

 <?php wp_kses($string$allowed_html$allowed_protocols); ?> 

Parameters

$string
(string) (required) Content to filter through kses
Default: None
$allowed_html
(array) (required) List of allowed HTML elements
Default: None
$allowed_protocols
(array) (optional) Allow links in $string to these protocols.
Default: The default allowed protocols are http, https, ftp, mailto, news, irc, gopher, nntp, feed, and telnet. This covers all common link protocols, except for javascript, which should not be allowed for untrusted users.

Return

(string) 
Filtered string of HTML.

Examples

Allowed HTML Tags Array

This is an example of how to format an array of allowed HTML tags and attributes.

array(
    'a' => array(
        'href' => array(),
        'title' => array()
    ),
    'br' => array(),
    'em' => array(),
    'strong' => array(),
);

Notes

  • KSES is an iterative acronym and stands for “KSES Strips Evil Scripts".

Change Log

  • Since: 1.0.0

Source File

wp_kses() is located in wp-includes/kses.php.

Related

See: Data Validation article for an in-depth discussion of input and output sanitization.

See also index of Function Reference and index of Template Tags.