I'm trying to show the category name in my category.php but it's not working when I have posts assigned to multiple categories as it chooses the first category.
<h1><?php $cat = get_the_category(); echo $cat->cat_name; ?></h1>
So I tried by using another method which is to show the category name using the slug URL but that shows nothing.
<h1><?php $cat = get_category_by_slug( $slug ); echo $cat->name; ?></h1>
Basically, I want someone opening
example.com/category/team to see
example.com/category/projects to see
<h1>Projects</h1> irrespective of the posts being assigned to multiple categories.
What am I doing wrong?