Php 高级自定义字段-在Woocommerce模板上显示youtube视频

Php 高级自定义字段-在Woocommerce模板上显示youtube视频,php,wordpress,youtube,advanced-custom-fields,Php,Wordpress,Youtube,Advanced Custom Fields,我已经设置了一个自定义字段,您可以通过wordpress中的文本小部件将youtube链接的结尾添加到该字段中,然后一个函数将其添加到url中的iframe中 下面是将此添加到页面的函数: <?php if (($videoUrl = get_field('video_name', $post->ID)) != '') { //Extract the url arguments (everything after the '?'

我已经设置了一个自定义字段,您可以通过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&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
            </div>
            <?php 
        }
    }
} ?>

使用高级自定义字段在wordpress模板中显示Youtube视频

1) 在acf中创建文本字段。 示例:文本字段名称为视频\ U url

2) 请在acf文本字段中输入youtube视频链接

3) 显示wordpress模板页面中的任意位置

<?php // use inside loop
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
?>

使用高级自定义字段在wordpress模板中显示Youtube视频

1) 在acf中创建文本字段。 示例:文本字段名称为视频\ U url

2) 请在acf文本字段中输入youtube视频链接

3) 显示wordpress模板页面中的任意位置

<?php // use inside loop
echo $youtubevideo_code = wp_oembed_get( get_field('video_url') );
?>


什么是$videoId return检查iframe和match的
src
url,是否为预期的youtube url…什么是$videoId return检查iframe和match的
src
url,是否为预期的youtube url。。。