Posted by KaiseRCrazY on 15th September 2009

Detect User Browser And Apply A StyleSheet

You can detect user/visitors browser type and you can apply browser-base css styleshet for your theme. That’s siple and very useful. Firstly you have add this code below to your theme’s function.php. Let’s Begin…

We will change our functions.php. If you don’t know about WordPress coding or PHP dont touch this file. And Make backup if you know about WP and PHP!

Her is the code;

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

After that you can save and upload to your fileserver. And you can create for all browser-base css files. And you can use this code with your body class like the example;

<body class="home blog logged-in safari">

That’s all! Have a nice day!

  • del.icio.us
  • Digg
  • Facebook
  • FriendFeed
  • Reddit
  • StumbleUpon
  • Technorati
  • PDF
  • Print

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No comments yet!

Post your comments