WordPress Stripping iFrame Elements? Here’s the Fix.
Elements like Google Map embeds get stripped out. Here’s the Fix.
If you have ever tried to enter a Google Map embed into a WordPress page or post, you’ve noticed that switching between “Visual” and “HTML” view in the page or post edit window strips the iFrame out–leaving you with broken code that displays nothing. Luckily, there is a fix.
You’ll need to find the functions.php file in your active theme folder. It’s a standard WordPress file, so it’ll be there. Next, we are going to add two short functions that change the way the WordPress editor handles iFrame code. You’ll want to insert the following lines of code before the closing “?>” of your functions.php file.
// this function initializes 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; } // this function alters the way the WordPress editor filters your code add_filter('tiny_mce_before_init', 'add_iframe');
That’s it. You can test your mod by entering some iFrame code in the editor window and switching between the visual and HTML editor.