Wordpress Taxonomy title output Wordpress Taxonomy title output wordpress wordpress

Wordpress Taxonomy title output


Found this answer for anyone else wondering.

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

Right down the bottom, the line wanted was:

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


can be done superdupereasy with:

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

name, when beeing on some custom taxonomy page, will be the taxonomy term., e.g. on something like example.com/books/Fiction, this will echo fiction.

Instead of name you could also use taxonomy, which will echo books.

And shortly spoken, taxonomies are NOT categories or pages or comments, they are something you declare, like "products" or "books". Using that you unlock WordPress'es Custom Post Type functionality. You can make your own archive-products.php, page-products.php, single-products.php and have big fun with it. :)


Here is a complete example, which modifies the title only for taxonomy listing pages, using the function is_tax()

<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>