wpexplorer

Add Portfolio taxonomy To Body Class

Aug 30th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // add classes to body based on custom taxonomy portfolio_cats
  2. function wpex_port_tax_body_class( $classes ) {
  3. if('portfolio' == get_post_type() ) {
  4. global $post;
  5. $terms = get_the_terms( $post->ID, 'portfolio_cats' );
  6. if($terms) {
  7. foreach ($terms as $term) {
  8. $term_classes[] = 'portfolio-' . $term->slug;
  9. }
  10. $classes = array_merge( $classes, $term_classes );
  11. }
  12. }
  13. return $classes;
  14. }
  15. add_filter( 'body_class', 'wpex_port_tax_body_class' );
Advertisement
Add Comment
Please, Sign In to add comment