You Are Here: Home » How-To » Programming

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

By on January 14th, 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');

--




         Submit to Reddit     Stumble


Related Posts by Tags: , , , , ,



  • Pingback: Twilight sweethearts Edward and Bella finally get intimate on Breaking Dawn honeymoon | Well Bite Me!!

  • Pingback: Alicia Silverstone’s Baby Bump | Well Bite Me!!

  • http://twitter.com/KrAzyChe3To Adam Christiansen

    Wow, thanks so much! I can’t believe YouTube would enable their iframes while something as big as WordPress will be doing this (removing the video in visual each time) for each and every blog out there that posts videos, Thanks so-SO much for this BIG fix!!

    • Anonymous

      Glad we were of help :-)

  • Mike

    Really appreciated good sir! I simply can’t believe how terrible TinyMCE is configured in wordpress, it’s ludicrous how much tinkering with the source you have to do to get it working properly. Removing line breaks! Idiots!

    • Anonymous

      Agreed! TinyMCE is messed up on WordPress :( And I am really glad that my article was of help to you :-)

  • Kuteo

    Thanks and regards

    • Anonymous

      Welcome :-)

  • Gino

    you’re the best!

    • Anonymous

      Thanks :-)

  • Wisemonkeysblog.com

    cannot thank you enough for this…

  • http://www.healthfulsense.com/ Lisa

    Thank you! Thank you! It worked :)

  • Anonymous

    excellent post.  This has bugged me for a long time.. Navigating from HTML to WSIWYG and suddenly the new Youtube IFRAME video code disappears.  What an annoying problem!  I hope this gets auto fixed in a later WordPress update.

  • Pingback: Insérer des iframes dans ses pages sous Wordpress | .:: Jikan ::.



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