Divi Page Builder

The Ultimate Web Design Toolkit!

Claim the discount before it disappears!

How To Stop WordPress Editor From Removing YouTube iFrame Tags

Eggbedded

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:

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

SOURCE: Thanks to Flick Nepal. PHOTO: Saicode

Divi Visual Page Builder

The Ultimate WordPress Toolkit. Complete Access!

For a short time only, we are offering you 10% off your membership.
Claim the discount before it disappears!

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

Comments are closed.

Scroll to Top
Copy link