Last active
December 21, 2017 18:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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