Add parent category name in body class for portfolio single page
Always use child theme any wordpress website and copy below code and add this code in your function.php for all portfolio categories single page. Use this below categories code for display portfolio or post all categories single blog page.
function woo_custom_taxonomy_in_body_class( $classes ){
$custom_terms = get_the_terms(0, 'portfolio-category');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
// Check if the parent category exists:
if( $custom_term->parent > 0 ) {
// Get the parent product category:
$parent = get_term( $custom_term->parent, 'portfolio-category' );
// Append the parent class:
if ( ! is_wp_error( $parent ) )
$classes[] = 'product_parent_cat_' . $parent->slug;
}
$classes[] = 'product_cat_' . $custom_term->slug;
}
}
return $classes;
}
add_filter( 'body_class', 'woo_custom_taxonomy_in_body_class' );
add parent category name to body class in post single page for use this code on worpress function.php file.
0 Comments