I've gone through other posts here, but have been unsuccessful making this work
I think I need a push at the fundamental starting point for this, as I can't seem to convert the resulting output into its adjoining label.
When looking at a Taxonomy Term Archive page, I would like to display the Top Level Taxonomy Name above the output.
With the following code, if I have a Taxonomy 'Kitchen Features', slug 'kitchen-features' - and I am on a Term Archive for this Taxonomy (i.e. Dishwasher) this code will output 'kitchen-features'. I need instead 'Kitchen Features'.
I thought I could achieve this with the addition of ->labels->name but evidently not applying it properly. So below I am showing the code to the point of returning 'kitchen-features', what do I need to do with $taxonomy to reach the Label? Thanks for any thoughts
private function get_taxonomy_by_term_id( $term_id ) {
// We can't get a term if we don't have a term ID.
if ( 0 === $term_id || null === $term_id ) {
return;
}
// Grab the term using the ID then read the name from the associated taxonomy.
$taxonomy = '';
$term = get_term( $term_id );
if ( false !== $term ) {
$taxonomy = $term->taxonomy;
}
return trim( $taxonomy );
}