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
Elegant Themes
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 »

Comments

  1. Nechemya K says:

    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.

  2. Aaron says:

    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.

  3. Pete says:

    I just use this inside the loop

  4. Saad says:

    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 .

  5. Frank Pereiro says:

    This is really, really nice.

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

    Thank you very much for sharing

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.