最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - How can I grab the video id of youtube?

programmeradmin1浏览0评论

I tried $videoID = wp_oembed_get( get_post_meta( get_the_ID(), 'video_url', true ) ); but that doesn't seem to do anything. I'm trying to set playlist id as the video id so the video loops itself.

function imp_custom_youtube_querystring( $html ) {
    if(strpos($html, 'youtube')!= FALSE) {
        $args = [
            'rel' => 0,
            'showinfo' => 0,
            'modestbranding' => 1,
            'loop' => 1,
        ];
        $videoID = wp_oembed_get( get_post_meta( get_the_ID(), 'video_url', true ) );
        $params = '?version=3&playlist='.$videoID.'&';
        foreach($args as $arg => $value){
            $params .= $arg;
            $params .= '=';
            $params .= $value;
            $params .= '&';
        }
        $result = str_replace( '?version=3', $params, $html );
    }
    return $result;
}
add_filter('video_embed_html', 'imp_custom_youtube_querystring', 10, 3);
发布评论

评论列表(0)

  1. 暂无评论