For categories/taxonomies you can use get_queried_object
to get the current category. From there you can easily get the name. So from your example:
if ( is_category() ) {
$cat = get_queried_object();
$heading = $cat->name;
}
For categories/taxonomies you can use get_queried_object
to get the current category. From there you can easily get the name. So from your example:
if ( is_category() ) {
$cat = get_queried_object();
$heading = $cat->name;
}