我想添加一个短代码,将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
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_xxx"]