Home › Forums › Front-end Issues › Hide HTML when field in empty › Reply To: Hide HTML when field in empty
Hi @soroshd
You need some more if-statements 🙂
Save all values to variables, then check wether ANY of those exists. then check each one.
<?php if( have_rows('social_media', 'option') ): ?>
<?php while( have_rows('social_media', 'option') ): the_row(); ?>
<?php
$fb = get_sub_field('facebook');
$tw = get_sub_field('Twitter');
$li = get_sub_field('LinkedIn');
?>
<?php if( $fb || $tw || $li ): ?>
<ul>
<?php if( $fb ): ?>
<li><a href="<?php echo $fb; ?>">Facebook</a></li>
<?php endif; ?>
<?php if( $tw ): ?>
<li><a href="<?php echo $tw; ?>">Twitter</a></li>
<?php endif; ?>
<?php if( $li ): ?>
<li><a href="<?php echo $li; ?>">LinkedIn</a></li>
<?php endif; ?>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.