Hi,
I am trying to use the advanced custom fields plugin in the single.php of my theme to embed youtube videos.
Here is the code
<object width="350" height="196"><param name="movie" value="http://www.youtube.com/v/<?php $field = get_field('video_link'); ?> ?version=3&&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="never"></param><param name="allownetworking" value="internal"></param><param name="enableJSURL" value="false" /><param name="enableHREF" value="false" /><embed src="http://www.youtube.com/v/<?php $field = get_field('video_link'); ?> ?version=3&&rel=0" type="application/x-shockwave-flash" allowscriptaccess="never" allowfullscreen="true" allownetworking="internal" enablehref="false" width="350" height="262"></embed></object>
The above code does not display the video id from the custom field.
The human editor creates a post, pastes the video id into the custom field (video_link).
The custom field is then called by single.php and displays the video.
I had this working before, but it was messy concatenations and multiple php variables.
Any help correcting the code so the video_link field displays properly would be appreciated
To see an example
[[LINK href="http://www.higherthinkingtv.com/psychology/big-bang-theory-sheldon-practices-operant-conditioning/"]][[/LINK]]
Basilis Kanonidis answers:
You are not "echoe" the value:
<?php echo $field = get_field('video_link'); ?>
Arnav Joy answers:
use echo before $field
try this
<object width="350" height="196"><param name="movie" value="http://www.youtube.com/v/<?php echo $field = get_field('video_link'); ?> ?version=3&&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="never"></param><param name="allownetworking" value="internal"></param><param name="enableJSURL" value="false" /><param name="enableHREF" value="false" /><embed src="http://www.youtube.com/v/<?php echo $field = get_field('video_link'); ?> ?version=3&&rel=0" type="application/x-shockwave-flash" allowscriptaccess="never" allowfullscreen="true" allownetworking="internal" enablehref="false" width="350" height="262"></embed></object>
Arnav Joy comments:
or try this
<object width="350" height="196"><param name="movie" value="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, 'video_link', true) ?> ?version=3&&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="never"></param><param name="allownetworking" value="internal"></param><param name="enableJSURL" value="false" /><param name="enableHREF" value="false" /><embed src="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, 'video_link', true) ?> ?version=3&&rel=0" type="application/x-shockwave-flash" allowscriptaccess="never" allowfullscreen="true" allownetworking="internal" enablehref="false" width="350" height="262"></embed></object>
Navjot Singh answers:
Replace this
<?php $field = get_field('video_link'); ?>
with
<?php echo get_post_meta($post->ID, 'video_link', true) ?>
ag123 comments:
Hi Navjot,
That worked!
Luis Abarca answers:
What about this, to support HTML5 and iOS devices
<iframe width="350" height="196" style="border:0" src="http://www.youtube.com/embed/<?php echo get_field('video_link') ?>"></iframe>