Created
May 26, 2015 08:47
-
-
Save moughamir/7ad07b18514d639f2030 to your computer and use it in GitHub Desktop.
Mobile Detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add to functions.php | |
// version proof, checks if the visitor is from a mobile device | |
function muneeb_wp_is_mobile() { | |
if ( function_exists( 'wp_is_mobile' ) ) | |
return wp_is_mobile(); | |
//code from wp_is_mobile function, wp_is_mobile() is located in wp-includes/vars.php version 3.4 | |
static $is_mobile; | |
if ( isset($is_mobile) ) | |
return $is_mobile; | |
if ( empty($_SERVER['HTTP_USER_AGENT']) ) { | |
$is_mobile = false; | |
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.) | |
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false | |
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false | |
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false | |
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false | |
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) { | |
$is_mobile = true; | |
} else { | |
$is_mobile = false; | |
} | |
return $is_mobile; | |
} | |
// Use anywhere | |
if ( muneeb_wp_is_mobile() ){ | |
//do mobile stuff here | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment