In the function websitez_detect_mobile_device in functions.php of WP Mobile Detector there is the detection of a mobile device (smartphone). Now I want that my Samsung Galaxy Tab (GT-P5100) is not treated as a smart phone. It should not redirect the user and the user should get the desktop version.

The user agent according to whatsmyuseragent.com is:

Mozilla/5.0 (Linux; U; Android 4.0.3;de-de;GT-P5100 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30

How can I add an exception for this device?

Can I use this code?

case (preg_match('/GT-P5100/i',$user_agent)); //Android
    $mobile_browser = false;
    $mobile_browser_type = "0"; //Tablet

Or is there a better way?

1 Answer 1


By means of preg_match and the like you can only write rules for specific devices (in your case the GT-P5100). What you want to do, however, is to affect only your device (meaning: not all Galaxy Tabs).

I'd vote for setting a cookie and act upon it's particular value:

setcookie('no_mobile_theme_please', 1, time()+60*60*24*30, '/', $_SERVER['SERVER_NAME'], false, false);

Then, you can check for the cookie:

if (isset($_COOKIE['no_mobile_theme_please']) && (1 == $_COOKIE['no_mobile_theme_please'])) ...

If the plugin does not allow for this (i.e., handling an exception cookie), you either have to adapt the code yourself, or you might want to write the author about your issue. Or maybe the plugin offers you a hook, so that you can realize your exception that way...?

  • That is the question how I can adapt the code (or add a hook). I still would need the detection of the device and here I could use the same mechanism like the plugin (see my code above). I thought someone had already done that but contacting the theme author is an option. But my example code could work but I have to test it.
    – testing
    Mar 26, 2013 at 8:14
  • This $mobile_browser variable in your code example, is this a global variable of the plugin? If so, then that's all you need. Or where do you want to place the code? Maybe I got you wrong...?
    – tfrommen
    Mar 26, 2013 at 9:05
  • It seems so that this is the global variable. I would place the code either inside the Android detection or after it (overwriting the settings). But I never tested it. Is this the right way? I mean that I would only change the encoding of one device (a certain Galaxy Tab). It would be better to recognize all Android tablets with a resolution higher than 1024px ...
    – testing
    Mar 26, 2013 at 9:18
  • To be honest, it ssem that you want to do more than you should do when using a plugin for a peculiar task. If this plugin shows any mobile device the mobile theme, but you would like to handle this resolution based, you might want to search for another plugin - or do it yourself right from the start. Anyway, your code example won't work. When introducing a case, you have to end the line with a colon :, not a semicolon. Then, preg_match returns bool (meaning true/false), so why do you want do check this (inside a switch)? The whole thing seems a little off.
    – tfrommen
    Mar 26, 2013 at 10:08
  • The thing is that an iPad is recognized well as tablet and you can set an option to exclude tablets. In my case the Galaxy Tab is recognized as smartphone ... But I think I'll leave it as it is. The semicolon is in the code of the plugin author. It is inside a switch statement.
    – testing
    Mar 27, 2013 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.