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
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.