Posted By

diegochavez on 09/28/10


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ddavidd


Detect the visitor browser within WordPress


 / Published in: PHP
 

URL: http://www.catswhocode.com/blog/10-useful-new-wordpress-hacks

Well, this hack is not so new, but it still remains one of my favorites. What this code does is pretty simple, it detects the name of the visitor browser and adds it to the body_class() function.\\r\\nThat way, you can correct browser-specific problems extremely easily. The function has to be pasted in your functions.php file.

  1. add_filter('body_class','browser_body_class');
  2. function browser_body_class($classes) {
  3. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  4.  
  5. if($is_lynx) $classes[] = 'lynx';
  6. elseif($is_gecko) $classes[] = 'gecko';
  7. elseif($is_opera) $classes[] = 'opera';
  8. elseif($is_NS4) $classes[] = 'ns4';
  9. elseif($is_safari) $classes[] = 'safari';
  10. elseif($is_chrome) $classes[] = 'chrome';
  11. elseif($is_IE) $classes[] = 'ie';
  12. else $classes[] = 'unknown';
  13.  
  14. if($is_iphone) $classes[] = 'iphone';
  15. return $classes;
  16. }

Report this snippet  

You need to login to post a comment.