function isMobile() { if (isTablet()) { //I just want mobile devices return false; } $detect = new Mobile_Detect(); return $detect->isMobile(); //return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); }
<?php // end analytics ?> <script type="text/javascript"> var templateUrl = '<?php echo get_template_directory_uri(); ?> '; var prodPrice = 0; var siteUrl = '<?php echo site_url(); ?> '; var isTablet = '<?php echo isTablet(); ?> '; var isMobile = '<?php echo isMobile(); ?> '; if(isTablet){ //the different actions are just for mobile devices isMobile=false; } </script> </head>
function mobileCheck() { $categorizr = DIR_SYSTEM . 'library/categorizr.php'; $device = DIR_SYSTEM . 'library/device.php'; if (file_exists($categorizr)) { require_once $categorizr; if (isMobile() || isTablet()) { return true; } } elseif (file_exists($device)) { if (!function_exists('deviceIsMobile')) { function deviceIsMobile() { $mobile = false; if (isset($_SERVER['HTTP_USER_AGENT'])) { $mobile_agents = array('iPod', 'iPhone', 'webOS', 'BlackBerry', 'windows phone', 'symbian', 'vodafone', 'opera mini', 'windows ce', 'smartphone', 'palm', 'midp'); foreach ($mobile_agents as $mobile_agent) { if (stripos($_SERVER['HTTP_USER_AGENT'], $mobile_agent)) { $mobile = true; } } if (stripos($_SERVER['HTTP_USER_AGENT'], "Android") && stripos($_SERVER['HTTP_USER_AGENT'], "mobile")) { $mobile = true; } } return $mobile; } } if (!function_exists('deviceIsTablet')) { function deviceIsTablet() { $tablet = false; if (isset($_SERVER['HTTP_USER_AGENT'])) { $tablet_agents = array('iPad', 'RIM Tablet', 'hp-tablet', 'Kindle Fire', 'Android'); foreach ($tablet_agents as $tablet_agent) { if (stripos($_SERVER['HTTP_USER_AGENT'], $tablet_agent)) { $tablet = true; } } if (stripos($_SERVER['HTTP_USER_AGENT'], "Android") && stripos($_SERVER['HTTP_USER_AGENT'], "mobile")) { $tablet = false; } } return $tablet; } } if (deviceIsMobile() || deviceIsTablet()) { return true; } } else { return isset($_COOKIE['is_mobile']) && (int) $_COOKIE['is_mobile'] == 1; } return false; }
<?php } ?> <?php if (!isMobile()) { ?> This device is <span class="not">not</span> a mobile <br /> <?php } ?> <?php if (!isTablet()) { ?> This device is <span class="not">not</span> a tablet <br /> <?php } ?> <?php if (!isDesktop()) { ?> This device is <span class="not">not</span> a desktop <br /> <?php } ?>