Browser body class


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1.  
  2. // Lägger till vilken browser man har, plus vilken version (om IE)
  3. add_filter( 'body_class', function($classes){
  4. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  5.  
  6. if($is_lynx) $classes[] = 'lynx';
  7. elseif($is_gecko) $classes[] = 'gecko';
  8. elseif($is_opera) $classes[] = 'opera';
  9. elseif($is_NS4) $classes[] = 'ns4';
  10. elseif($is_safari) $classes[] = 'safari';
  11. elseif($is_chrome) $classes[] = 'chrome';
  12. elseif($is_IE) $classes[] = 'ie';
  13. else $classes[] = 'unknown';
  14.  
  15. if($is_iphone) $classes[] = 'iphone';
  16.  
  17. // IE version
  18. if($is_IE) {
  19. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  20.  
  21. if (count($matches) > 1)
  22. $classes[] = 'ie-'. round($matches[1]);
  23.  
  24. }
  25.  
  26. return $classes;
  27. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.