2017-04-20 122 views
1

我有一個簡碼專門爲YouTube添加嵌入了寫像這樣:YouTube添加參數到簡碼的iframe嵌入

// [iframe src="" scrolling="no" class="dynamicIframe" allowfullscreen="" style=""] 
add_shortcode('iframe', 'anc_shortcode_iframe'); 
function anc_shortcode_iframe($atts, $content = null) { 

extract(shortcode_atts(array(
    'src'    => '', 
    'scrolling'   => '', 
    'class'    => '', 
    'allowfullscreen' => '', 
    'style'    => '' 
), $atts)); 

return '<iframe src="' . $src . '"' . ($scrolling ? ' scrolling="' . $scrolling . '"' : '') . ($class ? ' class="' . $class . '"' : '') . ($allowfullscreen ? ' allowfullscreen="' . $allowfullscreen . '"' : '') . ($style ? ' style="' . $style . '"' : '') . '></iframe>'; 

} 

我想在添加一些默認參數的所有影片,而且無法似乎使它工作。喜歡的東西

?rel=0&list=youtubeplaylistid

+0

您是否對每個視頻都有相同的YouTube播放列表ID,或者是否要分別在每個短代碼中定義播放列表ID? – pomaaa

+0

整個網站的播放列表ID可以相同。 – Clare

回答

0

如果你想將它添加到視頻的網址,你可以做這樣的底部:

// [iframe src="" scrolling="no" class="dynamicIframe" allowfullscreen="" style=""] 
add_shortcode('iframe', 'anc_shortcode_iframe'); 
function anc_shortcode_iframe($atts, $content = null) { 

extract(shortcode_atts(array(
    'src'    => '', 
    'scrolling'   => '', 
    'class'    => '', 
    'allowfullscreen' => '', 
    'style'    => '' 
), $atts)); 

return '<iframe src="' . $src . '?rel=0&list=youtubeplaylistid"' . ($scrolling ? ' scrolling="' . $scrolling . '"' : '') . ($class ? ' class="' . $class . '"' : '') . ($allowfullscreen ? ' allowfullscreen="' . $allowfullscreen . '"' : '') . ($style ? ' style="' . $style . '"' : '') . '></iframe>'; 

} 

替換「youtubeplaylistid」與你的播放列表ID。