Support

Account

Home Forums General Issues Only show fields if not blank

Helping

Only show fields if not blank

  • I have some fields which I only wish to show if the fields are not blank.
    My code so far…

    <a href="<?php the_field('field_link'); ?>"><img src="<?php the_field('field_image'); ?>"></a>

    This works fine if someone has entered a value for both the link and image.
    Is it possible to not display anything if the fields are blank?

    I have tried various configurations to make this work with my above code and can’t get it to work.

  • Wrap the link and image inside of an if, which checks to see if both are not empty like this:

    <?php if ( get_field(‘field_link’) != “” && get_field(field_image) != “” ) { ?>
    “>“>
    <?php } ?>

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Only show fields if not blank’ is closed to new replies.