I am having trouble hiding a div when the input of a custom field is empty. This is the code I am using but can not seem to get it to work. The field that displays the content is _cmb_fe_wysiwyg

        if( empty( $post->post_content) ) {
        else {
              echo '<div id="ingredientsNeeded">';
                    echo '<h3>Ingredients</h3>';
                  echo wpautop( get_post_meta( get_the_ID(), $prefix . '_cmb_fe_wysiwyg', true ) ); 
                  echo '</div>';

1 Answer 1


I think what you are looking for is something like:

 <?php $post = get_post_meta($post->ID, '_cmb_fe_wysiwyg', true) ; if (!empty($post)) { ?>
        <div id="ingredientsNeeded">
              <?php echo wpautop( get_post_meta( get_the_ID(), $post . '_cmb_fe_wysiwyg', true ) );?>
  <?php } ?>

This will check that the value is empty and if so will hide the div

  • perfect that worked like a charm Jul 15, 2014 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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