我在WordPress中为自定义字段使用高级自定义字段插件,我试图通过在编写YouTube视频ID的地方再添加一个自定义字段来嵌入YouTube视频。我将下面的代码片段添加到了realted内容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>
我自己也遇到了这个问题,并找到了一个有效的解决方案!
字段类型不能是oembed,而必须是单行文本
然后它与这个代码一起工作:
<?php // use inside loop echo $youtubevideo_code = wp_oembed_get( get_field('video_url') ); ?>
在您的情况下不需要使用短代码,只需编写iframe
标签:
<iframe src="<?php echo $embedcode; ?>" width="600" height="350" frameborder="0"></iframe>