0

I can think of a way to do this with CSS, but I rather jsut do it in a much cleaner way and just not have the code appear at all if nothing is entered into the Custom Field on the backend. Heres the code:

<li class="price">
   <?php echo get_post_meta($post->ID, 'Price', true); ?>
</li>

And I tried this:

<?php if get_post_meta($post->ID, 'Price', true); { ?>
    <li class="price">
        <?php echo get_post_meta($post->ID, 'Price', true); ?>
    </li>
<?php } ?>
Joe Bobby
  • 2,803
  • 10
  • 40
  • 59

1 Answers1

0

You can do a simple check on the variable to see if it is not empty:

<li class="price">
   <?php echo (!empty($post->ID)) ? 'Price': 'empty'; ?>
</li>

Of if you want to do away with the <li> entirely if it is empty:

<?php echo (!empty($post->ID)) ? '<li class="price">Price</li>': ''; ?>
Fluffeh
  • 33,228
  • 16
  • 67
  • 80