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.








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.
The second snippet of code shows just how to do that.
I just use this inside the loop
<?php single_tag_title(); ?>
and this for the term/tag description
<?php $description = get_queried_object()->description; ?>
<?php echo $description; ?>
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.
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 .
This is really, really nice.
I wish there was more post on taxonomies like this one.
Thank you very much for sharing
We can definitely work on that