If custom field has content

/ Published in: PHP
Save to your folder(s)

Good for showing labels/descriptions that accompany custom fields when they are set, and avoiding lots of empty labels.
Eg: if there is no content set in the 'project-agency' field, don't show the label 'Agency:', but if there is, show it with the content.

Copy this code and paste it in your HTML
  1. <?php
  2. $themeta = get_post_meta($post->ID, 'project-agency', TRUE);
  3. if(!empty($themeta)):
  4. ?>
  6. <strong>Agency:</strong> <?php echo get_post_meta($post->ID, 'project-agency', true); ?>
  8. <?
  9. endif;
  10. ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.