虽然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'); |
//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
来源:
https://www.wpdaxue.com/wp-iframe-handler-youku-tudou.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32882.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57