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 :)

Advertisement

Related Stuff!

Published on: May 26, 2011,

This post is in: Micro Tutorials, Tutorials, Wordpress

Author

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

Leave a Response