How to Stop WordPress Editor from Removing iFrame and Embed Code


A few days ago, we published a post “14 Advanced Level Photoshop CS5 Video Tutorials” which consisted of 14 iframe/embeded videos from youtube, vimeo etc. But it’s a known issue that WordPress editor will remove the iFrame code as soon as the tab is changed from html to visual or vice versa.  This is a real problem needed to be sorted out – so I did a little googling and found several fixes for this issue.

Out of those solutions this one seems to work well for me, I found it here.

All you need to do is open your theme’s functions.php , which can be found at : wp-admin->Appearance->Editor and paste this code in it. Make sure not to paste it inside a function. Good practice is to always make a backup of your file you are about to edit, just in case you are not much familiar with coding stuff.


function mytheme_tinymce_config( $init ) {
 $valid_iframe = 'iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]';
 if ( isset( $init['extended_valid_elements'] ) ) {
  $init['extended_valid_elements'] .= ',' . $valid_iframe;
 } else {
  $init['extended_valid_elements'] = $valid_iframe;
 return $init;
add_filter('tiny_mce_before_init', 'mytheme_tinymce_config');

Let me know if that helps :)

Further Related Readings


Join the 98,750+ Subscribers

Subscribe and grab Free Ebook! Photoshop Crash Course!

We promise not to spam!

Ayaz Malik

I'm a coding geek, art lover, and a proud father. I'm running several online businesses; sometimes I take freelance projects to pay my coffee bills. you can find me here on twitter
All Articles by
  1. Toma May 28, 2011 at 2:02 am

    I haven’t tried it yet, but if this works a marriage proposal will be forthcoming.

    1. Tayyab May 28, 2011 at 12:15 pm

      This is the best comment I’ve seen so far on Designzzz. You Rock Toma!

    2. Ayaz Malik May 28, 2011 at 12:19 pm

      Thanks Toma!, Looking forward to hear from you if it worked or not as there is another way around it.

  2. Tobia June 24, 2011 at 7:27 am

    I tried but it works only admin profile.

    1. Ayaz Malik June 24, 2011 at 9:52 am

      Please make sure if its implemented properly. or see if you can see the vids fine on this page :
      because we are using the same code to keep our videos :)

  3. Ayman August 25, 2011 at 3:22 am

    it worked with me, thanks Ayaz :)

  4. jerel September 22, 2011 at 8:30 pm

    thanks this worked a treat!!

  5. Nooooo April 3, 2013 at 7:43 am

    Does not work for allowing iframes in WordPress 3.5.1.

    There IS no folder wp-admin–>Appearance on my wp 3.5.1

Comments are closed.

Copyrights © 2015 - Designzzz. All Rights Reserved