Pin It
Pages Menu
Categories Menu

Posted by on Dec 7, 2013 in Wordpress Tutorials | 0 comments

How to Detect Visitor Browser Type in WordPress With PHP Browser Detection Plugin

How to Detect Visitor Browser Type in WordPress With PHP Browser Detection Plugin

There are so many methods to serve specific data to certain web browsers. For example, we can use conditional comments for like below:


[code type=”html”]



We can also use JavaScript browser detect function. See here.

Modernizr is also here for us for patching the stuff that are not supported to certain browsers. Oh I forgot to mention, CSS Media Query, very useful for mobile browsers.

Note: This tutorial is just for WordPress. Note for custom PHP.

Above mentioned methods are client side methods. Sometimes, these are not the ideal solution. As this is a WordPress tutorial for detecting browser with server-side language “PHP“. You can download the plugin here.

This plugin is very handy and easy to use. Just you’ll have to install the plugin and tweek your template file.

In your template file, if you just needed all the information in a variable or array, just do like below:

//Get all information in array
$browserInfo = php_browser_info();
//Get browser version number
$browserInfo = get_browser_version();
//Get browser name
$browserInfo = get_browser_name();

You can also use template tags in your theme. See below:

For mobile

if(is_mobile()) { }

if(is_ipod()) { }

if(is_ipad()) { }

if(is_iphone()) { }

For browsers

Here $version is optional variable. You can leave it empty.

if(is_ie($version)) { /* anything */ };

if(is_opera($version)) { /* anything */ };

if(is_chrome($version)) { /* anything */ };

if(is_firefox($version)) { /* anything */ };

if(is_safari($version)) { /* anything */ };

Conditions for greater or less than a specific browser version

if(is_safari() && get_browser_version() >= 4) { /* anything */ };

if(is_ie() && get_browser_version() <= 10) { /* anything */ };

if(is_firefox() && get_browser_version() <= 19) { /* anything */ };

Tip: For custom PHP projects, you can use PHP get_browser() function.

Post a Reply

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