I am starting out with PHP for a WordPress and have written some code to put some social network icons in the footer. The way I have done it works, I'm simply calling the content of social network URL stored in the DB and if there is something the icon/link in the footer. But looks very inefficient to me, here is the code, does anyone know how to make it more efficient.
<?php
$social1 = of_get_option('fab_social_twitter_url');
$social2 = of_get_option('fab_social_facebook_url');
$social3 = of_get_option('fab_social_linkedin_url');
?>
<!-- divs for right social network icons column -->
<div class="eight columns">
<div class="social">
<ul>
<?php
if(!empty($social1)) {
?>
<li><a href="<?php echo of_get_option('fab_social_twitter_url'); ?>"><img src="<?php echo of_get_option('fab_social_twitter_icon'); ?>" alt="Follow us on Twitter"></a></li>
<?php
}
?>
<?php
if(!empty($social2)) {
?>
<li><a href="<?php echo of_get_option('fab_social_facebook_url'); ?>"><img src="<?php echo of_get_option('fab_social_facebook_icon'); ?>" alt="Follow us on Facebook"></a></li>
<?php
}
?>
<?php
if(!empty($social3)) {
?>
<li><a href="<?php echo of_get_option('fab_social_linkedin_url'); ?>"><img src="<?php echo of_get_option('fab_social_linkedin_icon'); ?>" alt="Follow us on Linkedin"></a></li>
<?php
}
?>
</ul>
</div>
</div>
From a performance point of view, I don't think that there is anything to optimize in here, three separate cases tested individually
Maybe: