How To Detect Visitors Web Browser Details Within WordPress Blog

Posted by

Hi,

Many wordpress theme is not supported perfectly in many web browsers. In order to detect the visitors’ web browser, you can use this hack. For that you need to add this code in functions.php file of your theme:

<?php
add_filter(‘body_class’,’browser_body_class’);
function browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;

if($is_lynx) $classes[] = ‘lynx’;
elseif($is_gecko) $classes[] = ‘gecko’;
elseif($is_opera) $classes[] = ‘opera’;
elseif($is_NS4) $classes[] = ‘ns4’;
elseif($is_safari) $classes[] = ‘safari’;
elseif($is_chrome) $classes[] = ‘chrome’;
elseif($is_IE) $classes[] = ‘ie’;
else $classes[] = ‘unknown’;

if($is_iphone) $classes[] = ‘iphone’;
return $classes;
}
?>
Once you update the functions.php the function will automatically add a CSS class to the body tag. Here is one example:

<body>

Now, you need to define the stylesheet according to the browser in style.css

That’s it!

Thanks,

Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.