0

I've been checking the docs but I only found a way to use different style sheet for phones and tablets.

Is there a way to create another different theme only for mobile phones and tablets? And I'm not talking about creating a "responsive" theme. It's not always ideal.

I would like to display different information and not only change the structure. And also, optimize the loading of the site removing unnecessary javascript files and so on.

Is there a proper way to do it? Or I would need to find my own way.

  • 1
    You could use wp_is_mobile but you must know that there is no 100% accurate method to detect device properties server-side, and wp_is_mobile is not 100% accurate. Responsive desing with a mobile first approach is the actaul web standard, using different templates or showing different information depending on the user device is a old school practice not recommended any more. – cybmeta Mar 2 '15 at 11:34
  • Just to add, wp_is_mobile() detects mobiles only, not tablets. Stick to responsive design. This is the only reliable method around. – Pieter Goosen Mar 2 '15 at 12:03
  • @cybmeta yeah, some people might argue its "old", but actually is that technique used by most of the bigger companies out there. This article shows very clearly why responsiveness is not the final solution, but just one step to reach it. – Alvaro Mar 2 '15 at 12:12
  • As said in that article: "This article is not against responsive web design. It’s against aiming for responsiveness in a way that leads to a weak implementation". So, take care of the responsive desing implementation. From my point of view it is actually, as Pieter said, the only reliable method around. Anyway, we can fall in a opinion based discussion here; you have the answer in wp_is_mobile or any of the several external libraries out there that detect smartphones and tablets and you have been warning about their weakness; now you have to decide. – cybmeta Mar 2 '15 at 12:50
  • @PieterGoosen if you add your response as an answer, I'll accept it. – Alvaro Mar 2 '15 at 12:53
1

It's doable with a user agent string "sniffer". Take a look at this project: http://mobiledetect.net

Mind you, this approach can be troublesome as most modern browsers can 'fake' their user agent strings. Also, this approach doesn't work to well with caching systems.

I've implemented it successfully on a project I worked on, and I know it's possible but it has some caveats. If you're willing to overlook those small problems, I personally think this is the way to go (at least until WordPress gives us the proper tools to create better [and faster] websites).

  • I know the script, but I was asking more for a "proper" solution from the WP developing tools. I guess there's no such thing then? – Alvaro Mar 2 '15 at 12:13
  • Not that I know of :) – cristian.raiber Mar 2 '15 at 13:04

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.