Skip to content

Instantly share code, notes, and snippets.

@mennwebs
Created March 22, 2020 10:20
Show Gist options
  • Select an option

  • Save mennwebs/dd247e1f3af4364df0b3b848edaf4cc3 to your computer and use it in GitHub Desktop.

Select an option

Save mennwebs/dd247e1f3af4364df0b3b848edaf4cc3 to your computer and use it in GitHub Desktop.
Add Category Name to body_class
/* Add Category Name to body_class */
add_filter('body_class','moss_add_category_to_single');
function moss_add_category_to_single($classes) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
$classes[] = 'category-' . $category->category_nicename;
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment