Skip to content

Instantly share code, notes, and snippets.

@carasmo
Last active December 21, 2017 18:21
Show Gist options
  • Save carasmo/3c54cdc2b81c210750dbf3c59b453de9 to your computer and use it in GitHub Desktop.
Save carasmo/3c54cdc2b81c210750dbf3c59b453de9 to your computer and use it in GitHub Desktop.
add to your functions.php or an included php file in your theme like helper functions or general
<?php
//IMPORTANT: don't add above
add_filter( 'body_class', 'yourprefix_category_slug_body_class_single' );
/**
* Add category body class to single posts any post type
*/
function yourprefix_category_slug_body_class_single( $classes ) {
if ( is_single() ) :
global $post;
foreach( ( get_the_category( $post->ID)) as $category ) :
$classes[] = 'category-'.$category->slug;
endforeach;
endif; //single post
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment