How to add Iframes in WordPress posts or pages

A friend of mine needed some help. He wanted to place iframes inside WordPress posts but WordPress removes those codes automatically. So I searched for solutions and found this pretty simple one. All you need to do is to add these 4-5 lines of code to functions.php located in your theme’s folder.

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_filter('tiny_mce_before_init', 'add_iframe');

You can get there by going Appearance -> Editor -> Theme Functions (functions.php). If there’s no functions.php you’ll have to create one (to do so you must login to FTP or to your cPanel and create a functions.php file by hand in theme’s folder and then place this code in it. Don’t forget to open and close php segment.

Now WordPress will not remove iframes from your posts or pages!
Hope it helps!

Tags: wordpress iframe, iframe wordpress, iframe in wordpress, iframe wordpress page, iframes in wordpress, wordpress iframe in page
WordPress 3.5 custom media upload path missing
When CSF firewal is enabled – ping reports lots of lost packets

Comments

  1. Nice solution.
    I still perfer to use a plugin because they offer even more than the default iframe.
    e.g. http://www.wordpress.org/plugins/advanced-iframe/
    does also allow to modify css and hide elements. This is pretty cool if you are stuck to a wordpress theme and want to have more space for your iframe.

    Maybe this helps too, Michael

Leave a Reply

Your email address will not be published / Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.