WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to display the custom field/meta data content with some html?

Usually i would use the following to just display the content...

<?php echo get_post_meta($post->ID, '_cmb__description',true);?>

However, when there is actually meta content i want it to appear within some html, but i only want that html to appear when there is meta data to appear?

<?php echo get_post_meta($post->ID,<div class="box">. '_cmb__description'. </div>,true);?>

Is this possible? I'm not that up to scratch with it all, so wasn't sure if it was doable at all.

share|improve this question
up vote 1 down vote accepted

Yes, just check if you got something back from the post meta:

$value = get_post_meta($post->ID, '_cmb__description',true);

if ( $value )
    echo "<div class='box'>$value</div>";
share|improve this answer
Perfect, thank you very much. – user4630 Oct 26 '12 at 15:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.