Get custom taxonomy term name on an archive page on WordPress

How to retrieve the term’s name when rendering a custom taxonomy route.

If you’re viewing a normal post category rendered through the archive.php template, you can use the single_cat_title() function to display the current category name. But when dealing with custom taxonomies it’s a bit different.

It is as simple as:

$tax = $wp_query->get_queried_object();
echo $tax->name