Skip to content

Instantly share code, notes, and snippets.

@roscabgdn
Created January 27, 2016 11:50
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 roscabgdn/effa90aa3383d58923c6 to your computer and use it in GitHub Desktop.
Save roscabgdn/effa90aa3383d58923c6 to your computer and use it in GitHub Desktop.
WordPress - add category class to body class
add_filter( 'body_class', 'body_class_example' );
function body_class_example( $classes ) {
if( is_single() ) {
foreach( get_the_category( get_the_ID() ) as $category )
$classes[] = 'cat-' . $category->category_nicename;
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment