I have a hierarchical taxonomy with lots of terms in hierarchical order.
No matter what term i'm viewing I'd like to be able to display the custom taxonomy name (as per what i've registered it as singular_name
) on that page. I've searched here and the WP forums to death but had no luck.
I found this but it only displays the slug, not the name...
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo $term->taxonomy;
I have a hierarchical taxonomy with lots of terms in hierarchical order.
No matter what term i'm viewing I'd like to be able to display the custom taxonomy name (as per what i've registered it as singular_name
) on that page. I've searched here and the WP forums to death but had no luck.
I found this but it only displays the slug, not the name...
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo $term->taxonomy;
Share
Improve this question
edited Jan 26, 2019 at 5:54
Pete
asked Jan 26, 2019 at 5:42
PetePete
1,0582 gold badges14 silver badges40 bronze badges
1 Answer
Reset to default 2get_taxonomy( $taxonomy_name )
will give you an object containing all of the taxonomy metadata:
$queried_object = get_queried_object();
$this_tax = get_taxonomy( $queried_object->taxonomy );
echo $this_tax->labels->singular_name;