Last active
October 6, 2015 01:41
-
-
Save UnaiYecora/4b67accd1b9ff03dd916 to your computer and use it in GitHub Desktop.
Add category name to body_class
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
add_filter('body_class','add_category_to_single'); | |
function add_category_to_single($classes) { | |
if (!is_admin() && is_single() ) { | |
global $post; | |
foreach((get_the_category($post->ID)) as $category) { | |
// add category slug to the $classes array | |
$classes[] = $category->taxonomy . '-' . $category->slug; | |
} | |
} | |
// return the $classes array | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment