Skip to content

Instantly share code, notes, and snippets.

@UnaiYecora
Last active October 6, 2015 01:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Add category name to body_class
add_filter('body_class','add_category_to_single');
function add_category_to_single($classes) {
if (!is_admin() && is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
// add category slug to the $classes array
$classes[] = $category->taxonomy . '-' . $category->slug;
}
}
// return the $classes array
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment