首页 > study_note > How to Embed Videoes in WordPress

How to Embed Videoes in WordPress

2011年11月6日 T 发表评论 阅读评论

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.

分类: study_note 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。