You Are Here: Home » How-To » Programming

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

By Debjit on January 31st, 2011 

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');



How To Add Or Insert iframe content in WordPress Editor (HTML Mode) was originally published on on January 14, 2011 - 1:45 am (Indian Standard Time)