A simple PHP function to determine if client is a mobile browser

Posted on Posted in Blog

With the proliferation of mobile devices comes the problem for template makers on how to make their web pages behave as desired when shown on these mobile devices. This is true with WordPress template coders as well as template coders of other platforms who should keep abreast with technology changes.

A solution to this problem would be: determine the browser used to present the web page and make corresponding changes to the html part giving the css (cascading style sheet). In short, use a different css file when the browser is mobile. And of course, make sure that the template you’re using is XHTML so you won’t have a problem when the css is placed since you’re only changing the CSS not the HTML.

Here is a function that comes handy when you want to determine the browser or the client type:

[php]
functions.php file and perhaps in the header.php file. An example could be:
[php]
rel=”stylesheet” type=”text/css”>
[/php]

On the snippet above, the cssformobile.css is the css file for mobile.

Leave a Reply

Your email address will not be published. Required fields are marked *