Last active
April 15, 2016 15:04
-
-
Save lenivene/790c874f3ac126ec35779b30652875ec to your computer and use it in GitHub Desktop.
Test if the current browser runs on a mobile device.
This file contains hidden or 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 | |
/** | |
* Test if the current browser runs on a mobile device. | |
*/ | |
function is_mobile() { | |
$argent = $_SERVER['HTTP_USER_AGENT'] ? $_SERVER['HTTP_USER_AGENT'] : null; | |
$mobile = false; | |
if ( empty( $argent ) ) { | |
$is_mobile = $mobile; | |
} elseif ( strpos( $argent, 'Android' ) !== false | |
|| strpos( $argent, 'BlackBerry') !== false | |
|| strpos( $argent, 'Kindle') !== false | |
|| strpos( $argent, 'Mobile') !== false | |
|| strpos( $argent, 'Opera Mini') !== false | |
|| strpos( $argent, 'Opera Mobi') !== false | |
|| strpos( $argent, 'Silk/') !== false ) { | |
$is_mobile = true; | |
} else { | |
$is_mobile = $mobile; | |
} | |
return $is_mobile; | |
} | |
if ( is_mobile() ) { | |
echo ' Mobile '; | |
}else{ | |
echo ' Desktop '; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment