Tech Tips. Gadgets. Gaming.

How To Stop WordPress Editor From Removing YouTube iFrame Tags


Embedding a YouTube video while creating a post has always been a problem. WordPress only allows adding iFrame code in HTML view. And if you switch back to Visual mode and click save, the whole iFrame code gets deleted.

To keep iframe tag from being deleted from your WordPress editor, place this code in your current theme’s functions.php file:


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

SOURCE: Thanks to Flick Nepal. PHOTO: Saicode

Get updates delivered straight to your inbox!

Enter your email address:


  1. Genius!!!!!!!!
    This fixes the issue with TinyMCE, completely.

  2. Wow that thing worked like a charm. Thanks a lot

Leave a Reply