我想添加一个短代码,以便将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部分。我希望有人愿意帮助我:)
发布于 2020-12-18 02:26:52
<?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“
https://stackoverflow.com/questions/65345822
复制相似问题