0

Is there any built-in method for displaying a different template based off of browser size device (i.e. mobile device detection)?

I've done some research and all I can find is a ton of plugins that do way more than I need them to. I essentially just need a way to add a /mobile directory to my theme, and display that theme for mobile users.

5
  • No, there is no way for php to know browser size. Apr 14, 2015 at 15:49
  • 1
    See this post Apr 14, 2015 at 15:51
  • Good information about the wp_is_mobile() function, but I'm not really looking to detect screen size. There are plenty of PHP mobile detects out there, I'm just looking for a way to integrate that with a mobile theme. I might be able to use wp_is_mobile() to figure something out. Apr 14, 2015 at 16:03
  • I don't really understand, based off of browser size and not really looking to detect screen size. Why don't you just go with a responsive design. Otherwise you need to look into filters like template_include to switch templates according to mobile or desktop using the wp_is_mobile() condition Apr 14, 2015 at 16:23
  • Sorry, I do so many responsive designs I didn't think about what I typed in the original post. I meant to say device, not browser size. I'd like to do a responsive design, but my client already has a mobile site build and just wants to re-purpose that for their WordPress blog. I think your suggestion should work. Apr 14, 2015 at 18:22

1 Answer 1

0

I ended up adding this to my head:

<?
if (wp_is_mobile()) {
    include(TEMPLATEPATH . "/mobile/index.php");
    return;
}
?>

And it worked out fine for my purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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