Last active
November 25, 2015 17:23
-
-
Save duroe5698/a452607ca78abff0fff5 to your computer and use it in GitHub Desktop.
Add Post Category Slug as Body Class WordPress Snippet
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
| <?php | |
| function add_category_name($classes = '') { | |
| if(is_single()) { | |
| $category = get_the_category(); | |
| $classes[] = 'category-'.$category[0]->slug; | |
| } | |
| return $classes; | |
| } | |
| add_filter('body_class','add_category_name'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment