Our Biggest Black Friday Sale Ever!

Take Astra theme to the next Level with customizability and flexibility.
Grab up to 40% OFF! Limited Time Offer.


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

The Most Popular Theme of All Time

Built for speed and fully optimized for performance!

2 thoughts on “How To Stop WordPress Editor From Removing YouTube iFrame Tags”


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top