0

I have social icons that are being set via my theme options in WP. Of course if they are not entered I am getting an Undefined Index error. I tried wrapping isset around which removes the error, but when my options panel is saved it shows all the icons? Even if they have not been set? Confused on how to do the isset correctly?

<ul class="social-icons">
<?php if ( $theme_global['social-twitter'] ) { ?>
<li><a class="social-twitter" href="<?php echo $theme_global['social-twitter']; ?>" title="<?php _e( 'View Twitter Profile', 'lang' ); ?>" target="_blank"><i class="fa fa-twitter"></i><div class="tooltip"><span>Twitter</span></div></a></li>
<?php } if ( $theme_global['social-facebook'] ) { ?>
<li><a class="social-facebook" href="<?php echo $theme_global['social-facebook']; ?>" title="<?php _e( 'View Facebook Profile', 'lang' ); ?>" target="_blank"><i class="fa fa-facebook"></i><div class="tooltip"><span>Facebook</span></div></a></li>
<?php } if ( $theme_global['social-linkedin'] ) { ?>
<li><a class="social-linkedin" href="<?php echo $theme_global['social-linkedin']; ?>" title="<?php _e( 'View Linkedin Profile', 'lang' ); ?>" target="_blank"><i class="fa fa-linkedin"></i><div class="tooltip"><span>Linkedin</span></div></a></li>
<?php } if ( $theme_global['social-pinterest'] ) { ?>
<li><a class="social-pinterest" href="<?php echo $theme_global['social-pinterest']; ?>" title="<?php _e( 'View Pinterest Profile', 'lang' ); ?>" target="_blank"><i class="fa fa-pinterest"></i><div class="tooltip"><span>Pinterest</span></div></a></li>
<?php } ?>
</ul>

Many thanks

0

Try this:

<?php 
 if ( isset($theme_global['social-twitter']) && '' != $theme_global['social-twitter'] ) { ?>
  <li><a class="social-twitter" href="<?php echo $theme_global['social-twitter']; ?>" title="<?php _e( 'View Twitter Profile', 'lang' ); ?>" target="_blank"><i class="fa fa-twitter"></i><div class="tooltip"><span>    Twitter</span></div></a></li>
<?php } ?>

First check by isset and then check if that value is empty. If it has value then display it.

  • That's awesome Nilambar. How would I do this for this type of code (again bringing up undefined index errors) - <?php echo $theme_global['google-tracking-code']; ?> – Will Drayton Sep 5 '14 at 15:35
0

That's awesome Nilambar. How would I do this for this type of code (again bringing up undefined index errors) -

<?php echo $theme_global['google-tracking-code']; ?> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.