How to Create Conditional “IF” Statements for WordPress Custom Meta Fields
Sometimes you would want to output content based on WordPress meta fields – and use conditions (statements) based on whether or not the meta fields have data, etc. In this example, we are using a meta field with the name: “youtube-video-id” and value: “abcd1234”.
Instructions
Add this code to your single.php
file (or similar).
<?php if (get_post_meta($post->ID, 'youtube-video-id', true)) : ?> <?php echo get_post_meta($post->ID, 'youtube-video-id', true) ?> <?php endif; ?>