Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. add_filter('body_class','add_category_to_single');
  2. function add_category_to_single($classes) {
  3. if (is_single() ) {
  4. global $post;
  5. foreach((get_the_category($post->ID)) as $category) {
  6. // add category slug to the $classes array
  7. $classes[] = $category->category_nicename;
  8. }
  9. }
  10. // return the $classes array
  11. return $classes;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement