How to Embed Videoes in WordPress

As usual, this supposed to be an easy task, just copy the embed codes and all should work out fine. But in wordpress it didn’t… it turns out to be a bug or an error or anything you name it. Once you copy the embed codes into the HTML mode and switch to the normal edit mode, the codes simply disappeared. So it really a painful experience for me if I want embed any videos in my post, it seems that wordpress only accept certain kind of the embed codes. I resort to Google and found an easy way to fix the problem, though I don’t know exactly why it worked.

Find your theme’s function.php file. It usually located in your wordpress fold/themes/your theme/function.php or you can find it in your wordpress board, Appearance–Edit–function.php. Copy the following codes into this file, make sure to put  them in the right place, do not insert them to some functions.

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

Now, everything should be O.K.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>