How to Show the Current Taxonomy Title, URL, and More in WordPress

How to Show the Current Taxonomy Title, URL, and More in WordPress

When customizing a WordPress theme, you may want to display the current taxonomy’s title, description, or URL on archive pages. For example, if a visitor lands on your “Technology” category or a “Genre” custom taxonomy page, showing this information helps them understand exactly where they are — and makes your site look more professional.

In this tutorial, we’ll show you step by step how to display the current taxonomy title, URL, and more in WordPress using simple PHP snippets.

Step 1: Open or Create the Right Template File

To show taxonomy information, you’ll first need to edit the correct template file.

Here’s how WordPress decides which file to use for taxonomy archives:

  • Category archives: category.php
  • Tag archives: tag.php
  • Custom taxonomies: taxonomy-{taxonomy}.php (for example, taxonomy-genre.php)
  • Fallback: If none of these exist, WordPress uses archive.php.

Open or create the appropriate file in your theme folder. If you’re editing a parent theme, always use a child theme so your changes aren’t lost during updates.

Step 2: Get the Current Taxonomy Object

Inside your taxonomy template, you can use the following function to retrieve the currently queried taxonomy term:

<?php 
  $term = get_queried_object();
?>

This code returns an object that contains all the information about the taxonomy term currently being viewed. You can then access different properties of that object.

Step 3: Display the Taxonomy Title, Slug, and More

Once you have the $term object, you can display its data using simple PHP variables.

Here’s a practical example:

<?php 
  $term = get_queried_object();
?>
<h1 class="taxonomy-title">
  <?php echo esc_html( $term->name ); ?>
  <span class="taxonomy-info">
    <?php echo esc_html( $term->taxonomy ); ?> (<?php echo esc_html( $term->count ); ?> posts)
  </span>
</h1>

<?php if ( ! empty( $term->description ) ) : ?>
  <p class="taxonomy-description">
    <?php echo esc_html( $term->description ); ?>
  </p>
<?php endif; ?>

This code will display:

  • The taxonomy name (e.g., “Technology”)
  • The taxonomy type (e.g., “Category”)
  • The number of posts in that term
  • The taxonomy description (if available)

You can then style .taxonomy-title, .taxonomy-info, and .taxonomy-description with your theme’s CSS.

Step 4: Access Other Taxonomy Properties

You can do the same using any of the following values from the $term object:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count
  • filter
  • meta

For example, if you want to display the taxonomy slug, you can write:

<?php echo esc_html( $term->slug ); ?>

Or, to show the taxonomy ID:

<?php echo esc_html( $term->term_id ); ?>

These properties let you build more advanced layouts — such as adding icons, counts, or custom meta fields — directly tied to your taxonomy data.

Step 5: Display the Taxonomy URL

If you’d like to show or use the archive URL of the current taxonomy term, use the get_term_link() function:

<?php 
  $term_link = get_term_link( $term );
  if ( ! is_wp_error( $term_link ) ) {
    echo '<a href="' . esc_url( $term_link ) . '">' . esc_html( $term->name ) . '</a>';
  }
?>

This safely retrieves the archive link for the current term — useful for breadcrumbs or navigation menus.

Step 6: Keep It Clean and Secure

A few best practices when working with taxonomy data:

  • Always use esc_html() and esc_url() when outputting data.
  • Work in a child theme to preserve customizations.
  • Test your code in a staging environment before updating your live site.
  • If you use custom taxonomies, make sure they are registered as 'public' => true so archives are accessible.

That’s it! You’ve learned how to show the current taxonomy title, URL, description, and other useful data in WordPress.

This simple technique can make your category, tag, and custom taxonomy pages much more engaging and SEO-friendly.

Next, you can explore:

  • How to create custom taxonomies in WordPress
  • How to add custom fields (meta) to taxonomy terms
  • How to design unique layouts for specific taxonomies

With just a few lines of PHP, you can make your WordPress taxonomy archives both functional and beautiful — giving users a clear sense of where they are within your site.

Leave a Reply

Your email address will not be published. Required fields are marked *