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.


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>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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