elegant themes

The ultimate guide to embedding HTML and iframes in WordPress – part 2

| April 7, 2011 | 3 Comments

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:

// make TinyMCE allow iframes
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!

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Category: Code Snippets

About Miriam Schwab: Miriam is the friendly CEO of illuminea, a WordPress design and development agency. Miriam is a huge fan of WordPress and has been using it for over five years now. In addition, Miriam and her team have been organizing the local Israeli WordCamp conferences for the past few years. View author profile.

Elegant WP Themes

Comments (3)

Trackback URL | Comments RSS Feed

  1. John Schultz says:

    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.

  2. Rocky says:

    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?

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

More in Code Snippets (7 of 32 articles)