我已经建立了一个自定义字段,您可以通过wordpress中的文本小部件在其中添加youtube链接的末尾,然后再通过函数将其添加到url中的iframe中。
下面是将其添加到页面的函数:
<?php if (($videoUrl = get_field('video_name', $post->ID)) != '') {
//Extract the url arguments (everything after the '?'
if (($query = parse_url($videoUrl, PHP_URL_QUERY)) != '') {
//Convert the arguments into an array for each access
parse_str($query, $arguments);
if (array_key_exists('v', $arguments)) {
//Create the embed code using the id from the 'v' argument
$videoId = $arguments['v'];
?>
<div class="videoContainer">
<iframe width="390" height="219" src="https://www.youtube.com/embed/<?= $videoId ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
<?php
}
}
} ?>
我已在内容中添加了此内容,但似乎仍未显示任何内容。有人可以帮我发现任何错误..
最佳答案
使用高级自定义字段在Wordpress模板中展示YouTube视频
1)在acf中创建文本字段。
示例:文本字段名称为video_url
2)请在acf文本字段中输入youtube视频链接。
3)显示在WordPress模板页面的任何地方
<?php // use inside loop
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
?>
关于php - 高级自定义字段-在Woocommerce模板上显示youtube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29135765/