【问题标题】:Shortcode for youtube videos wordpressyoutube 视频 wordpress 的简码
【发布时间】:2021-03-28 10:41:40
【问题描述】:

我想添加一个简码以将 youtube 视频添加到我的网站。我想用 cookiebot 屏蔽内容。

如果我添加一个没有任何短代码的 youtube 视频,代码如下所示:

<div class="cookieconsent-optout-marketing">
      Please 
    <a href="javascript:Cookiebot.renew()">accept marketing-cookies</a> to watch this video.
    
</div>
<iframe data-src="https://www.youtube.com/embed/xxxxxxxxxxx" data-cookieconsent="marketing" frameborder="0" allowfullscreen></iframe>

所以我很难使用简码。我只知道如何添加新的简码。到目前为止,这是我的简码:

<?php

function youtube_function()
{

    $output = '
           <div class="cookieconsent-optout-marketing">
             Please <a href="javascript:Cookiebot.renew()">accept marketing-cookies</a> to watch this video.
           </div>
           
           <iframe data-src="https://www.youtube.com/embed/xxxxxxxxxxx" data-cookieconsent="marketing" frameborder="0" allowfullscreen></iframe>';

    return $output;
}

add_shortcode('ytvideo', 'youtube_function');

?>

现在我想替换链接或者 xxxxxxxxxx 部分。我希望有人想帮助我:)

【问题讨论】:

    标签: php wordpress cookies shortcode


    【解决方案1】:
     <?php
    
    function youtube_function($atts) {
    
        extract(shortcode_atts( array(
            'video' => '',
        ), $atts ));
        
        $output = '
        <div class="cookieconsent-optout-marketing">
        Please <a href="javascript:Cookiebot.renew()">accept marketing-cookies</a> to watch this video.
        </div>
    
        <iframe data-src="https://www.youtube.com/embed/' . $video .'" data-cookieconsent="marketing" frameborder="0" allowfullscreen></iframe>';
    
        return $output;
    }
    
    
    
    add_shortcode('ytvideo', 'youtube_function');
    
    ?>
    

    以这种方式使用简码: [ytvideo video="id_of_video_xxxx"]

    【讨论】:

      猜你喜欢
      • 2017-12-13
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多