Support

Account

Home Forums Front-end Issues Hide field if empty

Helping

Hide field if empty

  • Hi!

    I am using this code to show field label and value:

    <?php $field_name = ( ‘youtube’ );
    $field = get_field_object($field_name);
    echo $field[‘label’] . ‘: ‘ . $field[‘value’]; ?> <br>

    Please help integrating code for hiding the field if it is empty. At the moment field label is still showing up if the field has no value.

    Thx!

  • I do not see “if” conditional there. Something like this, cannot test now.

    <?php if( get_field('youtube') ): ?>
    <?php 
    $field_name = ( ‘youtube’ );
    $field = get_field_object($field_name);
    echo $field[‘label’] . ‘: ‘ . $field[‘value’]; ?> <br>
    ?>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Hide field if empty’ is closed to new replies.