Show custom field if one exists

Often we have custom fields in containers ( DIV, SPAN etc. ) designed by CSS. Here's a solution for displaying custom field content, if one exists. 

<?php if ( get_post_meta($post->ID, 'custom-field-name', true) ) : ?>
<?php echo get_post_meta($post->ID, 'custom-field-name', true); ?>
<?php endif; ?>

Leave a Reply