I realised that Portfolio Categories aren\'t actually categories, but a custom taxonomy term with slug \'project-type\', hence the reason why the code wasn\'t working. To get the portfolio category added as a body class to single portfolio items, use the following code in your child themes functions file:
// Add custom taxonomy terms to body class function custom_taxonomy_in_body_class( $classes ){ if( is_singular() ) { global $post; $custom_terms = get_the_terms($post->ID, \'project-type\'); if ($custom_terms) { foreach ($custom_terms as $custom_term) { $classes[] = $custom_term->slug; } } } return $classes; } add_filter( \'body_class\', \'custom_taxonomy_in_body_class\' );
Hi guys,
I need to add the Portfolio category as a body class on single portfolio pages.
I usually use the following code to achieve this (from the WP codex), but it doesn\'t seem to work on Salient single portfolio pages:
It does however work on single post pages!
Please advise as to how to get this working for portfolio single pages.
OK, just figured this one out myself...
I realised that Portfolio Categories aren\'t actually categories, but a custom taxonomy term with slug \'project-type\', hence the reason why the code wasn\'t working. To get the portfolio category added as a body class to single portfolio items, use the following code in your child themes functions file: