Created
May 26, 2015 15:21
-
-
Save mattradford/2dda94af4bcae0290b79 to your computer and use it in GitHub Desktop.
Add Custom taxonomy 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
// Adapted from http://krogsgard.com/2012/wordpress-body-class-post-meta/ | |
add_filter('body_class','tend_custom_tax_body_class'); | |
function tend_custom_tax_body_class( $classes ) { | |
global $wp_query; | |
$postid = $wp_query->post->ID; | |
if ( is_single() ) { | |
$post_styles = 'post_style'; | |
$tax_terms = wp_get_object_terms( $postid, $post_styles ); | |
if (!empty( $tax_terms )) : | |
foreach( $tax_terms as $term ) { | |
$term_lower = strtolower($term->name); | |
$classes[] = 'post-style-'. $term_lower; | |
} | |
endif; | |
} | |
// return the $classes array | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment