WordPress优酷、土豆视频移动端自适应

文章目录

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

函数代码

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

  1. //Youku
  2. function wp_iframe_handler_youku($matches, $attr, $url, $rawattr) {
  3.     if (wp_is_mobile()) {
  4.         $height = 200;
  5.     } else {
  6.         $height = 485;
  7.     }
  8.     $iframe = '<iframe width=100% height=' . esc_attr($height) . 'px src="http://player.youku.com/embed/' . esc_attr($matches[1]) . '" frameborder=0 allowfullscreen></iframe>';
  9.     return apply_filters('iframe_youku', $iframe, $matches, $attr, $url, $ramattr);
  10. }
  11. wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).html#i', 'wp_iframe_handler_youku');
  12. // Tudou
  13. function wp_iframe_handler_tudou($matches, $attr, $url, $rawattr) {
  14.     if (wp_is_mobile()) {
  15.         $height = 200;
  16.     } else {
  17.         $height = 485;
  18.     }
  19.     $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>';
  20.     return apply_filters('iframe_tudou', $iframe, $matches, $attr, $url, $ramattr);
  21. }
  22. wp_embed_register_handler('tudou_iframe', '#http://www.tudou.com/programs/view/(.*?)/#i', 'wp_iframe_handler_tudou');
  23. //Remove zh_CN Default handler
  24. wp_embed_unregister_handler('youku');
  25. wp_embed_unregister_handler('tudou');

视频添加

虽然应该都知道但是还是说一下吧 直接在可视化下添加链接就 OK http://v.youku.com/v_show/id_XMTQzOTU2NDg1Mg==.html

© 版权声明
THE END
喜欢就支持以下吧
点赞0赞赏
分享
相关推荐
  • 暂无相关文章
评论 抢沙发