The ultimate guide to embedding HTML and iframes in WordPress – part 2
Recently, I wrote about how WordPress users can easily add media like YouTube videos to posts and pages by just inserting the URL of the page the media is on. But that functionality was limited to sites that are oEmbed providers. We are still left with the problem of not being able to insert non-oEmbed iframes in WordPress, like Google Forms for example. If you try to insert a Google Form in the WordPress editor, you may find that all of the HTML is stripped out and you’re just left with a lonely “Loading…” on your page.
Well, there’s a solution. There’s an awesome thread on WordPress StackExchange with a collection of code for the functions.php file, including the following:
add_filter('tiny_mce_before_init', create_function( '$a',
'$a["extended_valid_elements"] = "iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]"; return $a;') );
Copy and paste the code into your WordPress functions.php file, and now you can embed any ol’ iframe you want in your WordPress editor, and it won’t get stripped out!
Happy embedding!
Category: Code Snippets










Perfect! I was so tired of hard coding iframes into templates. Not at all user-friendly for the end user. This will work so much better. And I was just looking for something like this yesterday.
So glad it helped you John!
Hey guys, i tried adding this to the bottom of my functions.php in the wp-includes folder and it caused all kinds of issues. Can you give any further instruction?