Created
January 10, 2016 15:18
-
-
Save ivanhoe011/fb076bbb52a106401315 to your computer and use it in GitHub Desktop.
WP: Add category classes to <body>
This file contains hidden or 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','iii_inject_category_classs'); | |
| // add post's categories as css classes to <body> (with cat- prefix added) | |
| function iii_inject_category_classs($classes) { | |
| global $post; | |
| if ($post and is_single($post)) { | |
| foreach((get_the_category($post->ID)) as $cat) { | |
| $classes[] = 'cat-' . esc_attr($cat->category_nicename); | |
| } | |
| } | |
| return $classes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment