WordPress by default filters out potentially harmful and/or invalid HTML. But in some cases you might want some of that invalid HTML!
One of those cases occurred today when we needed to embed a Google Form in a post. To do so, Google provides you with HTML code that contains a iframe, but uh-oh! The iframe element is not allowed by default.
If you look in wp-includes/kses.php you see a variable called $allowedposttags. The array contains all the allowed tags, and their allowed attributes. So you could also change the allowed attributes for the already allowed elements if you so wish.
To include iframe in the list of allowed element I added the following code to my theme’s functions.php:
$allowedposttags["iframe"] = array(
"src" => array(),
"height" => array(),
"width" => array()
);
And something that is always requested is the ability to simply just paste the embed-code provided by YouTube or Vimeo without having it filtered out. To do so simply add this to your functions.php or plugin:
$allowedposttags["object"] = array(
"height" => array(),
"width" => array()
);
$allowedposttags["param"] = array(
"name" => array(),
"value" => array()
);
$allowedposttags["embed"] = array(
"src" => array(),
"type" => array(),
"allowfullscreen" => array(),
"allowscriptaccess" => array(),
"height" => array(),
"width" => array()
);
But if you want to embed Flash files in a more standard compliant and modern way, check out our Easy Flash Embed plugin instead!