L O A D I N G
Profile image
blog banner

Add visitor browser name in the body class function

You can easily detect browser using this function and add visitor browser name in the body class function .

Put this on your theme functions.php

add_filter('body_class','myfunction_browser_body_class');
function myfunction_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_browser';

	if($is_iphone) $classes[] = 'iphone';
	return $classes;
}

The sample output may like this

<body class="home logged-in ie">

Source: Snipplr.com