Skip to content

Instantly share code, notes, and snippets.

@thadallender
Created June 4, 2013 22:27
Show Gist options
  • Save thadallender/5710177 to your computer and use it in GitHub Desktop.
Save thadallender/5710177 to your computer and use it in GitHub Desktop.
Filter post_class to return terms from a custom taxonomy in WordPress
function custom_taxonomy_post_class( $classes, $class, $ID ) {
$taxonomy = 'pcategory';
$terms = get_the_terms( (int) $ID, $taxonomy );
if( !empty( $terms ) ) {
foreach( (array) $terms as $order => $term ) {
if( !in_array( $term->slug, $classes ) ) {
$classes[] = $term->slug;
}
}
}
return $classes;
}
add_filter( 'post_class', 'custom_taxonomy_post_class', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment