虽然WordPress能直接插入优酷、土豆的视频但是无法在移动端观看,于是乎笨笨就开始各种折腾终于找到了合适的解决办法
另外在说一句支持移动端自适应哦
函数代码
在主题函数文件function.php
里面添加以下代码即可,保证在最后一个?>
之前就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //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'); |
//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
效果浏览
注:WordPress大学 采用https链接,但是优酷不支持,所以以上是图片,如果要看真实的预览,请访问原文 http://www.hibenben.com/4462.html
本文WordPress如何解决优酷、土豆视频移动端观看问题并自适应到此结束。成功的关键在于相信自己有成功的能力。小编再次感谢大家对我们的支持!