Add HTML tags to the allowed tags list in WordPress

May 21, 2015

By default WordPress limits what HTML tags are allowed in post content. If tags that are not whitelisted are found in the content they will be stripped. It is possible add additional tags to the allowed list.

View allowed tags

To view the list of currently allowed tags you can use the following code:

[php]
add_action( ‘init’, function() {
echo allowed_tags();
});
[/php]

Add to the allowed tags

In this instance I need to allow the iframe tag. Be sure to also specify the allowed attributes:

[php]
add_action( ‘init’, function () {
global $allowedtags;

$allowedtags[‘iframe’] = array(
‘src’ => array(),
‘height’ => array(),
‘width’ => array(),
);
});
[/php]

Add allowed tags to the WP Editor

Using the above will allow the iframe tag in code, but what if you want to allow the iframe to be added using the post editor? There is another filter used by tinyMCE which also needs to be set:

[php]
add_filter(‘tiny_mce_before_init’, function( $a ) {
$a["extended_valid_elements"] = ‘iframe[src|height|width]’;
return $a
});
[/php]

5 thoughts on “Add HTML tags to the allowed tags list in WordPress

  1. Vivek (March 11, 2016)

    NIce article i was looking for this !!
    Complete HTML 5 Tags list

  2. Smith (May 28, 2016)

    Really informative article. Thank you!

  3. Buzz (September 4, 2016)

    Useful, it saves my life.

  4. John (May 8, 2017)

    I’ve tried adding this and other methods for allowing HTML to my theme’s functions.php and the kses.php, but when I add a form to a textarea field, WP strips all of the input tags. WHERE should this be put?

    1. Ben Lobaugh (blobaugh) (May 9, 2017)

      Hi John! I believe you can put this in the functions.php file in your theme. If that is not working create a plugin or put it in the mu-plugins directory.