You will need to use the ID value returned by $category[0]->category_parent and pass it through get_term() $category = get_the_category(); $category_parent_id = $category[0]->category_parent; if ( $category_parent_id != 0 ) { $category_parent = get_term( $category_parent_id, 'category' ); $css_slug = $category_parent->slug; } else { $css_slug = $category[0]->slug; } //ref:https://wordpress.stackexchange.com/users/8054/rachel-baker