百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【Wordpress相关】使用 WordPress 的 Embed 功能快速插入优酷视频,并支持全平台播放

发布时间:2020-09-17

作品分类:Wordpress相关  视频  插入  功能  插入  快速  功能  播放  支持

使用 WordPress 的 Embed 功能快速插入优酷视频,并支持全平台播放,

在 WordPress 的 的功能让你通过直接发布一个 URL(需要单独一行,纯文本,不带链接才行),就能把这个 URL 中的视频显示到 WordPress 博客上,并且会根据博客的布局调整视频的大小。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>

但是默认不支持国内的优酷这个视频分享网站,我根据 WordPress 的 Embeds 接口制作了下面的插件,让你的 WordPress 博客通过一行链接就能发布优酷的视频,而无需去查找优酷的复杂而麻烦的嵌入代码,并支持全平台播放。

<?php
/*
Plugin Name: 使用 WordPress 的 Embed 功能快速插入优酷视频,并支持全平台播放
Plugin URI: http://blog.wpjam.com/m/wordpress-embed-youku/
Author: Denis
*/
function wpjam_embed_youku_handler( $matches, $attr, $url, $rawattr ) {
    if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
        $width  = (int) $rawattr['width'];
        $height = (int) $rawattr['height'];
    } else {
        list( $width, $height ) = wp_expand_dimensions( 480, 400, $attr['width'], $attr['height'] );
    }
    return '<iframe width='. esc_attr($width) .' height='. esc_attr($height) .' src="http://player.youku.com/embed/'. esc_attr($matches[1]) .'" frameborder=0 allowfullscreen></iframe>';

}
wp_embed_register_handler( 'youku', '#http://v.youku.com/v_show/id_(.*?).html#i', 'wpjam_embed_youku_handler' );

你只需要把优酷视频的链接直接贴入到 WordPress 日志内容中即可显示视频,假设其中 XXXXXXX 是视频的 ID,那么插入方法是:

http://v.youku.com/v_show/id_XXXXXXXXXXXXX.html

或者

http://v.youku.com/v_show/id_XXXXXXXXXXXXX.html

已经集成该代码,已经使用 WPJAM Basic 的用户无需再次添加。


本站推荐使用的主机:,国外主机建议使用

Top