您的位置:首页 > 移动开发

WordPress解决优酷、土豆视频移动端观看问题并自适应

2017-09-20 08:41 302 查看
转:https://www.xhsay.com/wp-iframe-handler-youku-tudou.html

虽然WordPress能直接插入优酷、土豆的视频但是无法在移动端观看,于是乎笨笨就开始各种折腾终于找到了合适的解决办法
另外在说一句支持移动端自适应哦。

函数代码

在主题函数文件function.php里面添加以下代码即可,保证在最后一个?>之前就好了

//Youku
function wp_iframe_handler_youku($matches, $attr, $url, $rawattr) {
if (wp_is_mobile()) {
$height = 200;
} else {
$height = 485;
}
$iframe = '<iframe width=100% height=' . esc_attr($height) . 'px src="http://player.youku.com/embed/' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
return apply_filters('iframe_youku', $iframe, $matches, $attr, $url, $ramattr);
}
wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).html#i', 'wp_iframe_handler_youku');
// Tudou
function wp_iframe_handler_tudou($matches, $attr, $url, $rawattr) {
if (wp_is_mobile()) {
$height = 200;
} else {
$height = 485;
}
$iframe = '<iframe width=100% height=' . esc_attr($height) . 'px src="http://www.tudou.com/programs/view/html5embed.action?code=' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
return apply_filters('iframe_tudou', $iframe, $matches, $attr, $url, $ramattr);
}
wp_embed_register_handler('tudou_iframe', '#http://www.tudou.com/programs/view/(.*?)/#i', 'wp_iframe_handler_tudou');
//Remove zh_CN Default handler
wp_embed_unregister_handler('youku');
wp_embed_unregister_handler('tudou');


视频添加方法


虽然应该都知道但是还是说一下吧 直接在可视化下添加链接就OK
http://v.youku.com/v_show/id_XMTQzOTU2NDg1Mg==.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: