Created
October 8, 2012 09:51
-
-
Save remkus/3851741 to your computer and use it in GitHub Desktop.
Function to add category nicenames to body class
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 | |
| add_filter( 'body_class', 'tax_body_class' ); | |
| /** | |
| * This function adds category nicenames to body class. | |
| * | |
| * @access public | |
| * @author Remkus de Vries | |
| * @param mixed $classes | |
| * @return void | |
| */ | |
| function tax_body_class( $classes ) { | |
| if ( is_singular('post') || is_category() ) { | |
| global $post; | |
| $terms = get_the_terms( $post->ID, 'category' ); | |
| if ( $terms && ! is_wp_error( $terms ) ) { | |
| foreach ( $terms as $term ) { | |
| // assign body class for the blog categories | |
| $classes[] =$term->slug; | |
| } | |
| } | |
| } | |
| return $classes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment