Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
You should wrap your HTML inside of your conditional to keep the list item from displaying. –  Brian Fegter Sep 21 '11 at 10:23
    
@BrianFegter: thanks. I did change the code. –  booota Sep 21 '11 at 10:36
add comment

Your Answer

 
discard

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.