Created
August 27, 2018 15:02
-
-
Save w-jerome/8a670aaa5fb990cc2a16537ca0f169a1 to your computer and use it in GitHub Desktop.
WordPress and PHP — Detect is Mobile
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
function isMobile() { | |
if (function_exists('wp_is_mobile')) { | |
if (wp_is_mobile()) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
if (preg_match('/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i', $_SERVER['HTTP_USER_AGENT'])) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment