ACF Hide Field if Empty

How to ignore or hide a field if it has no value?

This comes in handy with fields that are not required by the CMS user to fill out and will sometimes remain blank.

<?php if (get_field('email')): ?> 
   <?php the_field('email'); ?> 
<?php endif; ?>

Or if it is a sub field inside of the repeater loop.

<?php if (get_sub_field('email')): ?> 
   <?php the_sub_field('email'); ?> 
<?php endif; ?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s