Skip to content

Instantly share code, notes, and snippets.

@eyecandy91
Created August 18, 2016 11:44
Show Gist options
  • Save eyecandy91/d2b043541ec540bcedad9d60734f7443 to your computer and use it in GitHub Desktop.
Save eyecandy91/d2b043541ec540bcedad9d60734f7443 to your computer and use it in GitHub Desktop.
conditionally load content php via user agents
<?php
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
//do something with this information
if( $iPod || $iPhone ){ ?>
<?php//browser reported as an iPhone/iPod touch -- do something here ?>
<a class="sticky-footer" href="#" target="_blank">
<img src="<?php echo get_stylesheet_directory_uri(); ?>where/the/img/path/is.png" alt="">
</a>hello
<?php } else if($iPad){ ?>
<?php //browser reported as an iPad -- do something here ?>
<a class="sticky-footer" href="#" target="_blank">
<img src="<?php echo get_stylesheet_directory_uri(); ?>where/the/img/path/is.png" alt="">
</a>
<?php } else if($Android){ ?>
<?php //browser reported as an Android device -- do something here ?>
<a class="sticky-footer" href="#" target="_blank">
<img src="<?php echo get_stylesheet_directory_uri(); ?>where/the/img/path/is.png" alt="">
</a>
<?php } else if($webOS){ ?>
<?php //browser reported as a webOS device -- do something here ?>
<a class="sticky-footer" href="#" target="_blank">
<img src="<?php echo get_stylesheet_directory_uri(); ?>where/the/img/path/is.png" alt="">
</a>
<?php } else{?>
<?php //browser reported as a desktop or anything apart from the ones in questions -- do something here ?>
<a class="wrapper" href="#" target="_blank">
<img src="<?php echo get_stylesheet_directory_uri(); ?>where/the/img/path/is.png" alt="">
</a>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment