wordpress 插入视频短代码 支持优酷,土豆,ku6,youtube

在wordpress中有很多种方法插入视频,当wp自带的插入视频又比较笨,当然也有一些插件像Wordpress Video Plugin,smart-video,这些插件用起来也很不 "听话",你说我首页要输出摘要的,你也播放视频,这就不靠谱了…..

所以就自己动手下,做了几个短代码,直接插入视频,支持幽哭网,土豆片网,kuSix,一直被墙的youtube,在浏览该文章时插入视频。

幽哭版:


/**
*短代码调用方式
*简单版:[youku code="XXX"]
*默认视频大小为480X400,可添加width,height属性改变视频大小
*自定义版:
*[youku code="XXX" width="100" height="100"]
*/

function play_youku($atts){
extract(shortcode_atts(array(
'code'=>'',
'width'=>'480',
'height'=>'400'
),$atts));
$flash = '.$width.'" height="'.$height.'" type="application/x-shockwave-flash" data="http://player.youku.com/player.php/sid/'.$code.'/v.swf">';
if(is_single()){
return $flash ;
}
return '';
}
add_shortcode('youku', 'play_youku');
 

土豆片版:

/**
*短代码调用方式
*简单版:[tudou code="XXX"]
*自定义版:
*[tudou code="XXX" width="100" height="100"]
*/

function play_tudou ( $atts ) {
extract (shortcode_atts ( array (
'code' => '' ,
'width' => '480' ,
'height' => '400'
) , $atts ) ) ;
$flash = '.$width.'" height="'.$height.'" type="application/x-shockwave-flash" data="http://www.tudou.com/v/'.$code.'/v.swf">' ;
if (is_single ( ) ) {
return $flash ;
}
return '' ;
}
add_shortcode ( 'tudou' , 'play_tudou' ) ;
 

kuSix:

/**
*短代码调用方式
*简单版:[ku6 code="XXX"]
*自定义版:
*[ku6 code="XXX" width="100" height="100"]
*/

function play_ku6 ( $atts ) {
extract (shortcode_atts ( array (
'code' => '' ,
'width' => '480' ,
'height' => '400'
) , $atts ) ) ;
$flash = '.$width.'" height="'.$height.'" type="application/x-shockwave-flash" data="http://player.ku6.com/refer/'.$code.'/v.swf">' ;
if (is_single ( ) ) {
return $flash ;
}
return '' ;
}
add_shortcode ( 'ku6' , 'play_ku6' ) ;
 

youtube版:

/**
*短代码调用方式
*简单版:[youtube code="XXX"]
*自定义版:
*[youtube code="XXX" width="100" height="100"]
*/

function play_youtube ( $atts ) {
extract (shortcode_atts ( array (
'code' => '' ,
'width' => '480' ,
'height' => '400'
) , $atts ) ) ;
$flash = '.$width.'" height="'.$height.'" type="application/x-shockwave-flash" data="http://www.youtube.com/v/'.$code.'&hl=en_US&fs=1&autoplay=1">' ;
if (is_single ( ) ) {
return $flash ;
}
return '' ;
}

add_shortcode ( 'youtube' , 'play_youtube' ) ;
 

使用时可下载video.php,解压出video.php上传到主题文件夹,并在主题文件夹functions.php 添加以下语句

include_once('video.php');

来源:http://www.xbc.me/wordpress-shortcode-for-insert-video/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值