Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

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

Last updated on by
Follow WPBeginner on YouTube
How to Show the Current Taxonomy Title, URL, and more in WordPress

Recently one of our users reported an issue with their theme. They had a share button on all pages including the archive pages. However, the taxonomy archive page share buttons were showing the information of the most recent post instead of the actual taxonomy archive. We took a look at their code just to find out that they were calling the_permalink(); and the_title(); tag which are reserved for posts not archive pages. In this article, we will show you how to get the current taxonomy title, url, and other information on the specific taxonomy archive page.

All you have to do is paste the following code on your taxonomy archive page.

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 

This gets the information of the current taxonomy based on the archive page you are on. For example, if you were on a category page called “business”, then it will get the information for that taxonomy.

After that line of code, you can use it to display the title of the taxonomy and other info like this:

echo $term->name; // will show the name
echo $term->slug; // will show the slug

You can use it for the all of the following values:

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

We hope that this will help other theme designers who might need this. It can come in handy to show the current taxonomy title or any of the other information.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Nechemya K

    Hi.
    I trying to build a website for movies.
    I have a few post types like movies, tv, and more
    And I have a few taxonomies like: directors. Stars. Year. And more.

    How can I make taxonomy pages to show only the movies post type title in the page?
    Because when I ask to show all post in this tax, all of the post from all types shown

    Thanks for you help.

  • Aaron

    The title and first paragraph promises directions on how to get the URL, yet I see no mention of how to do so in the article body.

    • http://www.wpbeginner.com Editorial Staff

      The second snippet of code shows just how to do that.

  • Pete

    I just use this inside the loop

    • Pete

      <?php single_tag_title(); ?>

    • Pete

      and this for the term/tag description
      <?php $description  =  get_queried_object()->description; ?>
      <?php echo $description; ?>

    • Pete

      This forum post might be useful too…
      http://wordpress.org/support/topic/how-to-display-custom-taxonomy-tags-outside-the-loop

      P.s. can wpbeginner please not have “Subscribe to WPBeginner Updates (Weekly Email)” ticked as default every time I post a comment, it’s very annoying, and a little unethical… thanks.

  • Saad

    You Made My Day I was looking for this for so long thank you guys very much :). it will really help me in building a new theme for my blog .

  • Frank Pereiro

    This is really, really nice.

    I wish there was more post on taxonomies like this one.

    Thank you very much for sharing

    • http://www.wpbeginner.com Editorial Staff

      We can definitely work on that :)