WordPress – get currenct category slug on category page
To get the current category details e.g. slug or id on the category page, use the following code.
this code will return category object-
$category = get_category( get_query_var( "cat" ) ); $cat_id = $category->slug; //other properties //term_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent, count, cat_ID, category_count, category_description, cat_name, category_nicename, category_parent
Fidnnig this post. It’s just a big piece of luck for me.