Wordpress: Detect Visitors Browser and output in body class


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



Copy this code and paste it in your HTML
  1. /**
  2.  * Detect Visitors Browser
  3.  *
  4.  **/
  5. add_filter('body_class','myfunction_browser_body_class');
  6. function myfunction_browser_body_class($classes) {
  7. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  8.  
  9. if($is_lynx) $classes[] = 'lynx';
  10. elseif($is_gecko) $classes[] = 'gecko';
  11. elseif($is_opera) $classes[] = 'opera';
  12. elseif($is_NS4) $classes[] = 'ns4';
  13. elseif($is_safari) $classes[] = 'safari';
  14. elseif($is_chrome) $classes[] = 'chrome';
  15. elseif($is_IE) $classes[] = 'ie';
  16. else $classes[] = 'unknown';
  17.  
  18. if($is_iphone) $classes[] = 'iphone';
  19. return $classes;
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.