Sometimes you need to display post-specific content using WordPress custom fields. In this example we will show you how you can display custom field data using conditional statements in the form of a youtube video embed. If the post has a “youtube-video-id” defined, the content will be rendered.
Instructions
Insert content as shown below.
<?php global $wp_query; $postid = $wp_query->post->ID; ?>
<?php if( get_post_meta($postid, 'youtube-video-id', true) ): ?>
<div class="video-item-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_post_meta($postid, 'youtube-video-id', true);?>?feature=oembed&autoplay=0" frameborder="0" allowfullscreen="">
</iframe>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
Comments