虽然WordPress能直接插入优酷、土豆的视频但是无法在移动端观看,于是乎贝贝就开始各种折腾终于找到了合适的解决办法,另外在说一句支持移动端自适应哦。
代码
在主题函数文件function.php里面添加以下代码即可,保证在最后一个?>之前就好了。
- // 虽然应该都知道但是还是说一下吧 直接在可视化下添加链接就OK
- // http://v.youku.com/v_show/id_XMTQzOTU2NDg1Mg==.html
- // 优酷支持移动端
- function wp_iframe_handler_youku($matches, $attr, $url, $rawattr) {
- if (wp_is_mobile()) {
- $height = 200;
- } else {
- $height = 485;
- }
- $iframe = ‘<iframe width=100% height=’ . $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’);
- // add tudou using iframe
- function wp_iframe_handler_tudou($matches, $attr, $url, $rawattr) {
- if (wp_is_mobile()) {
- $height = 200;
- } else {
- $height = 485;
- }
- $iframe = ‘<iframe width=100% height=’ . $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’);
- wp_embed_unregister_handler(‘youku’);
- wp_embed_unregister_handler(‘tudou’);
效果
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系贝贝进行处理。本站默认解压密码:www.hibbba.com


评论(0)