Skip to content

Instantly share code, notes, and snippets.

@jrstaatsiii
Created October 11, 2012 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrstaatsiii/3873314 to your computer and use it in GitHub Desktop.
Save jrstaatsiii/3873314 to your computer and use it in GitHub Desktop.
Add Category To Body Class
add_filter('body_class','add_category_to_single');
function add_category_to_single($classes, $class) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug to the $classes array
$classes[] = $category->category_nicename;
}
}
// return the $classes array
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment