I'd like to add a category class to body_class for custom post type to change body background color. I tried to rework the following code to work with custom post types, but no dice. It works with posts, but not the custom post type.
add_filter('body_class','add_category_to_single');
function add_category_to_single($classes) {
if (is_singular() ) {
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;
}
I'm using Pods plugin and the latest WP.