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:


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.

Tags: ,

WordPress SEO: 10 tips for better search rankings

FREE E-book. Learn the basics of WordPress SEO and how to improve the key metrics
  • We won't sell your address to anyone. We hate spam too.
View my portfolio Get in touch

2 Responses to “WordPress $is_iphone global”

  1. Simon Wheatley

    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.

    Reply
    • keithdevon

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

      Reply

Leave a Reply