17

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?
| improve this question | | | | |
16

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

| improve this answer | | | | |
  • 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
9

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.

| 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
7

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.

| improve this answer | | | | |
  • I upvoted your answer because consideration about cache are very important in my opinion too. – Marco Panichi Mar 29 '18 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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