0

Quite a simple question really, but unsure how to do it. I have this little bit of code:

<li><span>
            <?php if ( function_exists('get_custom_field_value') ){
                    get_custom_field_value('Essential info 5', true);
            } ?>
            </span></li>

...and I want to find out how I can adjust it so that if that particular field is empty, it does not display the list item at all.

Thanks!

0

use empty function to check if the return value is empty or not:

   <?php if ( function_exists('get_custom_field_value') ):
        $custom_field_value = get_custom_field_value('Essential info 5', true);
        if(!empty($custom_field_value)):
        ?>
        <li><span>
           <?php echo $custom_field_value; ?>
        </span></li>
        <?php
        endif;
   endif; ?>

also check if the function 'get_custom_field_value' is returning with echo statement, you may need to change that to just return the result and not to echo it out.

Hope it solves your problem.

  • You should wrap your HTML inside of your conditional to keep the list item from displaying. – Brian Fegter Sep 21 '11 at 10:23

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.