Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrfoxtalbot/d2ad2f66c3cd41a65ad5 to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/d2ad2f66c3cd41a65ad5 to your computer and use it in GitHub Desktop.
add_filter('body_class','mrfx_add_category_to_single');
function mrfx_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