Reputation: 423
I'm using Advanced Custom Fields plugin for custom fields in WordPress, and I tried to embed YouTube videos by adding one more custom fields where I write the YouTube video IDs. And I added the snippet below to the realted content php file, but it did not work. Could you please tell me what is wrong with the code? Thanks.
<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>
Upvotes: 0
Views: 10700
Reputation: 61
I had the problem myself and found a solution that worked!
the field type must not be oembed, but must be single-line text
and than it works with this code:
<?php // use inside loop echo $youtubevideo_code = wp_oembed_get( get_field('video_url') ); ?>
Upvotes: 2
Reputation: 847
You don't need to use shortcode in your case, just write iframe
tag :
<iframe src="<?php echo $embedcode; ?>" width="600" height="350" frameborder="0"></iframe>
Upvotes: 1