Skip to content

Instantly share code, notes, and snippets.

@mattradford
Created May 26, 2015 15:21
Show Gist options
  • Save mattradford/2dda94af4bcae0290b79 to your computer and use it in GitHub Desktop.
Save mattradford/2dda94af4bcae0290b79 to your computer and use it in GitHub Desktop.
Add Custom taxonomy to body class
// 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