WordPress自动获取文章内视频作为封面的方法

火币

火币

火币是全球三大交易所之一,虚拟货币交易平台安全可靠,注册领取新人礼包!

很多实用WordPress程序搭建视频站的站长都在吐槽用WordPress做视频方面体验就不是很友好的,为了改进后大大提升了站点的用户体验,需要实现自动提取文章内视频作为封面,今天就分享一下WordPress自动获取文章内视频作为封面的方法。

图片[1]-WordPress自动获取文章内视频作为封面的方法-玩转网 | 902D.Com

将下方代码添加进functions即可实现:

//提取视频封面

function catch_video_image() {

global $post, $posts;

$video_image = '';

ob_start();

ob_end_clean();

$output = preg_match_all('/<video.+poster=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

$video_image = $matches [1] [0];

return $video_image;

}

//正则提取字符串中视频url地址

function catch_that_video() {

global $post, $posts;

$first_video = '';

ob_start();

ob_end_clean();

$output = preg_match_all('/<video[^<>]*src=[\"]([^\"]+)[\"][^<>]*>/im', $post->post_content, $matches);

$first_video = $matches [1] [0];

return $first_video;

}

 

© 版权声明
THE END
点赞7赞赏 分享