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.

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');