可能是这样的:
function my_class_names($classes) {
$useragent = $_SERVER[\'HTTP_USER_AGENT\'];
if(strchr($useragent,\'Safari\')) $classes[] = \'Safari\';
// etc..
return $classes;
}
add_filter(\'body_class\',\'my_class_names\');
Edit - 根据Chip的建议,以下是使用WordPress用户代理检查的功能:
function my_class_names($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_winIE) $classes[] = \'winIE\';
elseif($is_macIE) $classes[] = \'macIE\';
elseif($is_opera) $classes[] = \'opera\';
elseif($is_NS4) $classes[] = \'NS4\';
elseif($is_safari) $classes[] = \'safari\';
elseif($is_chrome) $classes[] = \'chrome\';
elseif($is_iphone) $classes[] = \'iphone\';
else $classes[] = \'other\';
return $classes;
}
add_filter(\'body_class\',\'my_class_names\');