【问题标题】:Add YouTube Parameters into Shortcode for iFrame Embed将 YouTube 参数添加到 iFrame 嵌入的简码中
【发布时间】:2017-09-17 03:44:10
【问题描述】:

我有一个专门用于添加 YouTube 嵌入的短代码,如下所示:

// [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&amp;list=youtubeplaylistid

【问题讨论】:

  • 您会为每个视频使用相同的 YouTube 播放列表 ID,还是要在每个短代码中分别定义播放列表 ID?
  • 整个网站的播放列表 ID 可以相同。

标签: php wordpress iframe youtube shortcode


【解决方案1】:

如果您想将其添加到视频网址,您可以在底部这样做:

// [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。

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 1970-01-01
    • 2016-05-12
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 2016-08-30
    • 1970-01-01
    相关资源
    最近更新 更多