I’m looking to get desktop and mobile functionality in a single WordPress theme.
There are several solutions available that use a post/get method to send the screen size to php. For example: http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Now my question is how to implement this in WordPress. For reference, the PHP is structured like this:
index.php:
get_header();(header.php)
body
get_footer();(footer.php)
So the question is:
Is there any way to get the screen height/width/viewport into a PHP variable before get_header() gets called from index.php?
There are a few nice WP plugins available to detect mobile devices. My problem with those is that they use mostly user agent data that is hardly reliable. I want my design to change based on the users viewport. And for that i also need to manipulate the WordPress PHP calls in the theme.
Have you considered using media queries in CSS instead of programming via php?
This works if you are only targeting modern mobiles such as the iPhone and android devices.
e.g.
<link rel=”stylesheet” type=”text/css”
media=”screen and (max-device-width: 480px)”
href=”mobile.css” />