I am building a website on wordpress, the theme I’m using support the desktop and mobile. So the website change based on what the user is using. Anyway, I am trying to determined if the user is using mobile when browsing the website, based on what I have search so far,
echo $_SERVER['HTTP_USER_AGENT'];
This determined the information of something I’m not sure of. When I opened the header.php of my theme file. I did tried to removed these lines, and browse the website on mobile, the website did not appear as a mobile, it appear a FULL VIEW WEBSITE just like on a desktop, and that is the output I’m trying to work on.
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
The problem now is how can I determine if the user is on mobile or not? Any idea on this?
WordPress uses the
wp_is_mobile
function to check a mobile device. It doesn’t check what device is being used but the user agent can send some basic information to your site. WP docs: http://codex.wordpress.org/Function_Reference/wp_is_mobileTo get a “full view” version of your website there are two methods to achieve this… clever ways that don’t need you to have two copies of your website on different suddomains.
wp_is_mobile
function you could use this to dynamically put a link on your site to the “Desktop version” – using thewp_is_mobile
function to your advantage you could have it only add the “Desktop version” link if someone is using the mobile version of your site. -> You could then have a link with a$_GET
variable that you use in yourheader.php
to not echo the browser meta (you know when you removed the meta data and you got the full site on a phone?) so you should then have the ability to view the full site on a mobile.$_GET
variable that you can feed into yourheader.php
to not echo out the meta tag to change the site for mobile versions.The problem with a more “dynamic” method (as above) is that your CSS media queries will override and possibly cause you problems. An alternative is to host a copy of your site on a subdomain that hasn’t got any responsive CSS…
what are you exactly trying to achieve? Is it that smaller resolutions get an adapted website? If so test for the resolution.
If you are trying to adapt your website when certain capabilities are missing (flash, javascript, …) then you should test those.
Nowadays you can get Android on a laptop and you can change your browseragent on some android phones.
depends on how custom you want to go, but php has a built in function called get_browser()
from the php white pages,
will output something similar to
you can then make all sorts of design decisions based on that data. specifically the [platform] and [browser] for your task