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

Pin It on Pinterest

Share This