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

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

This could be the beginning of something great 🙌

Name
Hidden
Hidden

By submitting this form: You agree to the processing of the submitted data in accordance with WP Dynamics Privacy Policy.

Contact Information
You can also write us an email or contact us by telephone.
Telephone +45 71 74 71 21

Support For support inquiries, please refer to our support section.

Recent Articles

Faust.js – A Headless Framework for WordPress

Faust.js is a Headless WordPress Framework that provides a set of tools for building front-end applications based on WordPress ...

How to Load (Enqueue) and Handle Assets and Dependencies in WordPress

In WordPress, instead of adding assets such as styles and JavaScript to the header, you can and should use ...

An Introduction to Google Tag Manager Server-side Tagging

WordPress has come a long way since its launch in 2003 - from a blogging tool to a full-fledge ...