Ready to get started?Download WordPress


PHP Browser Detection
[resolved] is_mobile() not working after upgrade to 2.2 (9 posts)

  1. neilv247
    Posted 1 year ago #

    Using my laptop is_mobile() worked OK the previous version 2.1.2, returning false. After upgrade to 2.2 returns true.


  2. jdev
    Posted 1 year ago #

    Yep, got the same problem. Any solutions yet?

  3. fuchsws
    Posted 1 year ago #

    to fix this, search within "/wp-content/plugins/php-browser-detection/php-browser-detection.php":

    and replace line 278:
    if(isset($browserInfo['ismobiledevice']) && $browserInfo['ismobiledevice'] == (bool) 1) {
    if(isset($browserInfo['ismobiledevice']) && $browserInfo['ismobiledevice'] == 'true') {

  4. seltzdesign
    Posted 1 year ago #

    I had the same problem and luckily came across this forum post. This was posted 3 months ago and fixes a really important function, yet no update is available - Pretty shoddy.

  5. square_eyes
    Posted 11 months ago #

    I used this workaround/fix. Tested OK with Firefox OSX and Default Browser on Android. Thanks:)

    However, and this maybe a browscap or plugin problem, Firefox Android shows as desktop with the below code.

    <?php if(is_mobile()) {echo "Mobile";} else {echo "Desktop";} ?>

  6. square_eyes
    Posted 11 months ago #

    As does Chrome Android.

  7. ndenitto
    Posted 11 months ago #

    Hey guys. @fuchsws' fix looks correct. if you do:

    <?php var_dump( php_browser_info); ?>

    you'll notice that 'ismobiledevice' is a string, not a bool, so the is_mobile() function is broken, I think. Rather than change the plugin code, I use the following to detect for mobile:

    <?php $browser_info = php_browser_info(); ?>
    <?php if ( $browser_info['ismobiledevice'] == 'false' ) : ?>

    { desktop browser-specific code }

    <?php endif; ?>

    As for @square_eyes' noticing false positives on Android, I have not tested the above on Android, but it would be great if next version of this script had Android detect functions (like ipad, ipod, and iphone).

  8. Mindshare Studios, Inc.
    Plugin Author

    Posted 11 months ago #

    Thanks for the bug reports and sorry for the delay between updates. This will be fixed in the next version.

  9. square_eyes
    Posted 11 months ago #

    Great thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic