Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // add category identifiers in the body classes for product pages
- add_filter( 'body_class', 'add_body_classes' );
- function add_body_classes( $classes ) {
- global $post;
- // product pages only
- if ( is_product() ) {
- // get the categories for this product
- $terms = get_the_terms( $post->ID, 'product_cat' );
- foreach ($terms as $term) {
- // you can use either slug or id, no point having both
- $classes[] = 'cat_slug_'.$term->slug;
- $classes[] = 'cat_id_'.$term->term_id;
- }
- return $classes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement