Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

27

Jun

Browser Detection WordPress Functions

Browser Detection WordPress  Functions

Posted On : June 27, 2013

| No Comment

Providing cross-browser compatibility on your blog / website theme, you must have to be able to detect the browser used by the visitor.

Method

By using this conditional comments. WordPress itself can detect client browser.
Providing cross-browser compatibility on your blog / website theme, you must have to be able to detect the browser used by the visitor.

<!–?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 saved the file, the function will automatically add a CSS class to the body tag, as shown in the example below:

Screenshot

  • Tags:

Comment