An even better body_class for WordPress

by Moises Kirsch

Here is a little update to my better body_class code:

add_filter('body_class','better_body_class');
function better_body_class($classes){
	global $post, $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
	if($is_lynx){
		$classes[] = 'lynx';
		$classes[] = 'notie';
	}
	elseif($is_gecko){
		$classes[] = 'gecko';
		$classes[] = 'notie';
	}
	elseif($is_opera){
		$classes[] = 'opera';
		$classes[] = 'notie';
	}
	elseif($is_NS4){
		$classes[] = 'ns4';
		$classes[] = 'notie';
	}
	elseif($is_safari){
		$classes[] = 'safari';
		$classes[] = 'notie';
	}
	elseif($is_chrome){
		$classes[] = 'chrome';
		$classes[] = 'notie';
	}
	elseif($is_IE){
		$classes[] = 'ie';
	}
	elseif($is_iphone){
		$classes[] = 'iphone';
		$classes[] = 'notie';
	}
	else $classes[] = 'unknown';
	$other_classes = explode('/', get_page_uri($post->ID));
	return array_merge($classes, $other_classes);
}

So what does this thing do?

It adds a the slug of the current page to the class just like the old one but it also combines Nathan Rice code for browser detection with even a little extra class called notie a.k.a. Not Internet Explorer.

The notie class is very useful when you are debugging your CSS and trying to fix all the annoying things that IE doesn’t get right.