在WordPress上嵌入带有高级自定义字段的YouTube视频

时间:2016-05-11 18:42:47

标签: php wordpress embed

我在WordPress中为自定义字段使用高级自定义字段插件,我尝试通过添加一个自定义字段来嵌入YouTube视频,我在其中编写YouTube视频ID。我将下面的代码段添加到了经过验证的内容php文件中,但它没有用。你能告诉我代码有什么问题吗?感谢。



<div class="videoembed">
<?php $embedcode = the_field('video-embed'); 
 echo do_shortcode("[embedyt]http://www.youtube.com/watch?v=" .$embedcode. "&width=600height=350[/embedyt]"); ?>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

我自己遇到问题,找到了可行的解决方案!

字段类型不得为斜线,而必须为单行文本

,并且与此代码配合使用:

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

答案 1 :(得分:0)

您不需要在您的情况下使用短代码,只需写下iframe代码:

<iframe src="<?php echo $embedcode; ?>" width="600" height="350" frameborder="0"></iframe>
相关问题