WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm going to test the user agent to load a mobile template instead of the desktop theme.

There are many mobile detection scripts out there.

  • Does wp_is_mobile() function work well?
  • What is your experience in comparison with other classes like e.g. mobiledetect.net?
share|improve this question
up vote 14 down vote accepted

Yes it works well. It's a very simple function but never found a mobile device not recognized by it. It recognize the 90%+ of mobile devices. Main difference from mobiledetect.net is that doesn't differe from phone and tablets.

See the code

share|improve this answer
thank you, as always G.M. provides pro answers :) – Andrea Puiatti Aug 26 '13 at 14:46
thank you, Andrea @AndreaPuiatti – gmazzap Aug 27 '13 at 0:23
But as hint - 90% is not all, and 90% is only today. We get very fast new device and this function is often not helpful. You exclude devices, users from the solution. – bueltge Nov 18 '15 at 11:05

Yes, the wp_is_mobile() works well, but you can run into problems when using aggressive caching systems, such as fastcgi, proxy cache, etc. that skip the php execution.

If that is the case, I would recomend some client side (javascript) detection method that is loaded for both mobile and desktop browsers.

share|improve this answer
That's a good point. If you use full page caching in auto (per request) mode, the cache will contain mobile OR desktop version, depending on what device the first request was made from. All further requests will be served with this version, no matter what device type it is. If you use a pre-caching solution (which I always do), you'll get desktop versions generated and mobile users will always get them. – Ihor Vorotnov May 8 '15 at 14:53

It is a shitty idea to use that function. Device identification should always be done at the client side, and user agent is probably the worst way to identify whether a device supports a feature X or have a form factor Y.

You start using it when the site is young and then your site grows and you decide to cache your HTML and boom all your device detection code stops working..... Better not to walk down that ally in the first place.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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