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]
NIce article i was looking for this !!
Complete HTML 5 Tags list
Really informative article. Thank you!
Useful, it saves my life.
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?
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.