WordPress $is_iphone global

OK, why did nobody tell me about this, and why is it not documented!

I just found out today that WordPress does some browser detection of its own. I’ve previously relied on other code libraries for this, but maybe now I can use the ‘WordPress Way’.

Detecting mobile in WordPress using $is_iphone

In wp-includes/vars.php there is the following declaration:

[code lang=”php”]

global $pagenow,
$is_lynx, $is_gecko, $is_winIE, $is_macIE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $is_IE,
$is_apache, $is_IIS, $is_iis7;


So it looks like WordPress detects a number of browsers. The $is_iphone variable is interesting because it seems to work as a general ‘mobile’ detection. I have it working to detect the Android ‘Internet’ browser.

I’ll add more here as I play with the possibilities.

2 responses to “WordPress $is_iphone global”

  1. Simon Wheatley Avatar

    N.B. if you are running a static page caching system, like WP Super Cache, then detecting the browser in PHP like this might cause issues. The problem arises if a page is tailored for someone accessing on an iPhone and the page is then cached and served to someone not on an iPhone (or vice versa). You’ll be fine if you’re not running static page caching though, e.g. in the admin area.

    1. keithdevon Avatar

      Good point Simon. I haven’t actually used this variable in anger yet, but I was interested when I found it there in core.

Leave a Reply

Your email address will not be published.