I am using the following code within the footer of my test site. I am using WordPress and Advanced Custom Fields
The intention is:
To display the HTML container
.social-media--icons
if any of the fields contain content within the CMS.Then, within the container
.social-media--icons
, display the relevant icon andhref
if that field is filled.
I have included strlen(trim($twitter)) > 0
as I understand this will detect if the field only has spaces.
I appear to have this working locally and performing the above tasks. I am looking to find out if there is a clearer, optmisied method of performing these tasks
<div class="site-info">
<a id="toTopButton" href="#pageTop" class="to-top-button"><img src="<?php echo get_template_directory_uri(); ?>/svg/arrow.svg" alt="Up Arrow"></a>
<p>©
<?php echo date('Y'); ?></p>
<?php
$facebook = get_field('facebook', 'option');
$twitter = get_field('twitter', 'option');
$instagram = get_field('instagram', 'option');
?>
<?php if(isset($facebook) && strlen(trim($facebook)) > 0 || isset($twitter) && strlen(trim($twitter)) > 0 || isset($instagram) && strlen(trim($instagram)) > 0): ?>
<div class="social-media--icons">
<?php if(isset($facebook) && strlen(trim($facebook)) > 0): ?>
<a class="social-link ie9" href="<?php echo $facebook; ?>" target="_blank" rel="noopener">
<img src="<?php echo get_template_directory_uri(); ?>/svg/facebook.svg" alt="Facebook Icon">
</a>
<?php endif; ?>
<?php if(isset($twitter) && strlen(trim($twitter)) > 0): ?>
<a class="social-link ie9" href="<?php echo $twitter; ?>" target="_blank" rel="noopener">
<img src="<?php echo get_template_directory_uri(); ?>/svg/twitter.svg" alt="Twitter Icon">
</a>
<?php endif; ?>
<?php if(isset($instagram) && strlen(trim($instagram)) > 0): ?>
<a class="social-link ie9" href="<?php echo $instagram; ?>" target="_blank" rel="noopener">
<img src="<?php echo get_template_directory_uri(); ?>/svg/instagram.svg" alt="Instagram Icon">
</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>