Browser detection WordPress Tuttorial

Wpsnipp – PHP Browser Detection is a WordPress plugin used to detect a user’s browser. It could be used to send conditional CSS files for Internet Explorer, display different content or custom messages anywhere on the page, or to swap out flash for an image for iPhones.

Adding this PHP code to your functions.php will add a class on the body tag within your HTML document with the specific browser name.

 

 

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;
}

Be Sociable, Share!

Leave a comment