Body Classes for Styling WordPress Taxonomies

I recently noticed that WordPress does not seem to add style classes to the body tag for custom taxonomies in the same way that it does on category archives.

You can fix this by adding the following to your functions.php file.

function taxonomy_body_class( $classes ) {
	if ( is_tax() ) {
		$tax = get_query_var( 'taxonomy' );
		$term = $tax . '-' . get_query_var( 'term' );
		$classes = array_merge( $classes, array( 'taxonomy-archive', $tax, $term ) );
	return $classes;
add_filter( 'body_class', 'taxonomy_body_class' );

I don’t know why WordPress doesn’t do this automatically – I guess it should be added to core. What do you think?

fish oil omega 3

Ben Huson