Let me know whether wp_is_mobile
function will work with all the mobile and tablet devices ? Is it enough to check mobile device ?
I found that this method in wp-includes/vars.php
function wp_is_mobile() {
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;
}
If i need to develop any mobile site, whether i can use this method ?
Edit
Why wp uses server side script to detect mobile device ?
No, it will fail. There are literally thousands of mobile clients, and not all send a usable User-Agent header. There are better ways to adjust the site to small screens (which is not necessary the same as mobile!).
Use client side detection and offer a link to switch the view; save that option in a cookie.
I think the common misconception is that mobile == small screen. The Nexus 10 has more pixels than my big desktop screen, while my old laptop running a desktop Ubuntu shows just a 1024×768 pixels. Surface RT comes with 1366×768 pixels, a mouse (trackpad), a keyboard and a touch interface. And some UAs are just not detectable.
Which one will get the layout âoptimized for mobileâ?