WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Add parent category to body class on single page (2 posts)

  1. chocula
    Member
    Posted 10 months ago #

    I want to add the parent category on a single page so i can apply some specific styling for male and female. I have this code in the functions file:

    add_filter('body_class','wpa76627_class_names');
    function wpa76627_class_names( $classes ) {
        if( is_singular( 'product' ) ):
        global $post;
        foreach( get_the_terms( $post->ID, 'product_cat' ) as $cat )
            $classes[] = $cat->slug;
    endif;
        return $classes;
    }

    but it doesn't pick up the parent category, just the child category. How can i make it show the parent category instead.

    Thank you

    http://wordpress.org/extend/plugins/woocommerce/

  2. chocula
    Member
    Posted 10 months ago #

    i should have said above i want to add it as a body class on the page

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.