Skip to content

Instantly share code, notes, and snippets.

@robskidmore
Last active August 29, 2015 13:55
Show Gist options
  • Save robskidmore/8715546 to your computer and use it in GitHub Desktop.
Save robskidmore/8715546 to your computer and use it in GitHub Desktop.
Add body class based on custom taxonomy term
<?php
function add_taxonomy_term_as_body_classes( $classes ) {
global $post;
$terms = wp_get_post_terms($post->ID, '[taxonomy]', array("fields" => "all"));
foreach ($terms as $class ) {
$classes[] = $class->slug;
}
return $classes;
}
add_filter('body_class','add_taxonomy_term_as_body_classes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment