Wordpress Taxonomy Title Output

I am trying to display the title of a taxonomy page when viewing it.

So if I were on the tag page, I would go:

<?php if (is_tag()) {?> <h1><?php single_cat_title(); ?></h1> <?php } ?> 

But how would you achieve the same if the user views a particular taxonomy page?

is_taxonomy() does not exist.

+7
wordpress taxonomy
source share
5 answers

Found this answer for someone else.

Follow this guide: http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database

Right down, you need a line:

 <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?> 
+9
source share

can do superdupereasy with:

 <?php echo get_queried_object()->name; //output $taxonomy->$tax the simple way ?> 

name if a taxonomy term will be used on any page of a custom taxonomy. on something like example.com/books/Fiction , it will be an echo of fiction .

Instead of name you can also use taxonomy , which will be an echo of books .

And in short they say that taxonomies are NOT categories or pages or comments, this is what you say, for example, β€œproducts” or β€œbooks”. Using this, you unlock the functionality of Post Post Type WordPress. You can create your own archive-products.php , page-products.php , single-products.php and enjoy it. :)

+7
source share

Here is a complete example that changes the title only for taxonomy listing pages using the is_tax() function

 <title><?php global $page, $paged, $post; if (is_tax()) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $term_title = $term->name; echo "$term_title | "; } else { wp_title( '|', true, 'right' ); } // Add the blog name. bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); ?></title> 
+1
source share

You can use single_term_title () .

+1
source share

I think that just using the single_cat_title () function is enough.

See here for more details .

0
source share

All Articles