Display the taxonomy name of the current term

admin2025-06-04  2

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
Add a comment  | 

1 Answer 1

Reset to default 2

get_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;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748973878a315292.html

最新回复(0)