让wordpress直接插入Youku,Tudou,Youtube视频地址播放HTML5视频

让wordpress直接插入Youku,Tudou,Youtube视频地址播放HTML5视频

示例如下:
https:// www . youtube . com/watch?v=T_Vmq3ju0WE

将下面的代码添加到主题function.php文件中:

function content_html5video_replace($content =''){
$width = '560';$height = '315';

$search = $replace = array();
$search[] = '#http://www.tudou.com/programs/view/(.*?)/#i';
$replace[] = '<iframe src="http://www.tudou.com/programs/view/html5embed.action?code=\\1" width="'. $width .'" height="'. $height .'" frameborder=0 allowfullscreen></iframe>';

$search[] = '#http://v.youku.com/v_show/id_(.*?).html#i';
$replace[] = '<iframe src="http://player.youku.com/embed/\\1" width="'. $width .'" height="'. $height .'" frameborder=0 allowfullscreen></iframe>';

$search[] = '#https?://(www.)?youtube\.com/watch\?v=([^/<]+)#i';
$replace[] = '<iframe src="https://www.youtube.com/embed/\\2" width="'. $width .'" height="'. $height .'" frameborder=0 allowfullscreen></iframe>';

$content = preg_replace($search, $replace, $content);
return $content;
}
add_filter('the_content','content_html5video_replace');

Leave a Reply