Created
April 1, 2015 14:36
-
-
Save 3200creative/49c00a95d1c99909b4d6 to your computer and use it in GitHub Desktop.
Add Category To Body Class Of Singular Page
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 Category Type To Body Class Of Single Article */ | |
add_filter('body_class','add_category_to_single'); | |
function add_category_to_single($classes, $class) { | |
if (is_single() ) { | |
global $post; | |
foreach((get_the_category($post->ID)) as $category) { | |
// add category slug to the $classes array | |
$classes[] = $category->category_nicename; | |
} | |
} | |
// return the $classes array | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment