How to Stop WordPress Editor from Removing iFrame and Embed Code

How to Stop WordPress Editor from Removing iFrame and Embed Code

AD

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.

Code:

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

Ayaz Malik

Artist by soul, programmer by profession. I am a designer, developer and Publisher. Running a few blogs and publishing a lot of interesting stuff. you can find me here on twitter
All Articles by
8 Comments on “How to Stop WordPress Editor from Removing iFrame and Embed Code” Join The Discussion!
  1. Toma says:

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

    1. Tayyab says:

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

    2. Ayaz Malik says:

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

  2. Tobia says:

    I tried but it works only admin profile.

    1. Ayaz Malik says:

      Please make sure if its implemented properly. or see if you can see the vids fine on this page : http://www.designzzz.com/advanced-photoshop-cs5-video-tutorials/
      because we are using the same code to keep our videos :)

  3. Ayman says:

    it worked with me, thanks Ayaz :)

  4. jerel says:

    thanks this worked a treat!!

  5. Nooooo says:

    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 © 2014 - Designzzz. All Rights Reserved