How To Add Or Insert iframe content in WordPress Editor (HTML Mode)

Adding iframe content to your posts in Wordpress is simple. However, you won't be able to do this without a small tweak or else the rich text editor in Wordpress will strip down all your iframe tags and you will end up getting no rendered iframe content.

Sometimes using an iframe is the easiest way to embed content in your website. Even Youtube is testing an iframe embed mode along with the regular object embed. However you should always remember that iframes are not at all good from Search engine optimisation (SEO) point of view.

Adding iframe content to your posts in WordPress is simple. Just switch to the HTML mode and you can enter all the iframe code in there. But there is one catch. The rich text editor in WordPress will strip all iframe tags by default and you won’t we able to effectively render the iframe content.

So here is the fix. All you need to do is open the functions.php file which you can find in your WordPress theme’s folder, add the following code to the file and save it. After you do this, you will be able to add iframe content easily in the posts (in HTML  Mode) without the iframe tags getting stripped.

//function to initialise the iframe elements
function add_iframe($initArray) {
$initArray[‘extended_valid_elements’] = “iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]”;
return $initArray;
}



//add the function to the WordPress editor using filters
add_filter(‘tiny_mce_before_init’, ‘add_iframe’);

If this sounds like your situation, let's talk

No pitch decks. No sales process. Just a conversation about what you're dealing with and whether I can help.

Book a 30-minute call →