Lightweight detector of mobile devices, OSs & browsers
A really simple and very lightweight plugin to detect mobile devices, mobile OSs & mobile browsers.
This plugin adds the following global variables (boolean values) to WordPress:
Is it a mobile?
$is_mobileAny famous device?
$is_iphone (Apple iPhone)$is_ipad (Apple iPad)$is_kindle (Amazon Kindle)What mobile OS?
$is_android (Android OS)$is_bada (Bada OS)$is_bbos (Blackberry OS)$is_ios (Apple iOS)$is_palmos (Palm OS)$is_symbian (Symbian OS)$is_webos (Hp WebOS)$is_windows (Windows Phone OS and older)What mobile browser?
$is_firefox_mobile (Mozilla Fennec)$is_ie_mobile (IE)$is_netfront (NetFront)$is_opera_mobile (Opera Mobile or Mini)$is_uc_browser (UC Browser)$is_webkit_mobile (Webkit)The initial value of these variables is false.
How can I redirect a user to the mobile version of my site?
Easy, paste this snippet in your functions.php file:
function mobile_redirect() {
global $is_mobile;
if ( $is_mobile ) {
// replace URL_TO_MOBILE_SITE with your site's mobile URL i.e. http://mobile.example.com
header( 'Location: URL_TO_MOBILE_SITE' );
exit;
}
}
add_action('after_setup_theme', 'mobile_redirect');
Debugging
You can test/debug the plugin results (debug mode) here.
If you need to debug the plugin, you can do it calling the global function: margenn_mobile_detector(true). Calling this function will output the results.
Suggestions?, bugs? report them in the plugin forum.
Requires: 2.5 or higher
Compatible up to: 3.3.1
Last Updated: 2011-12-20
Downloads: 1,827




