You can create intuitive navigation structures and enhance user engagement on your website using categories, tags, and custom taxonomies. However, we believe a crucial element in user experience is providing clear context within each taxonomy archive page.
You can provide this context by showing relevant information directly on your archive pages in WordPress, such as the current taxonomy title, URL, and more.
In this article, we will show you how you can help users understand their location in your website hierarchy by displaying the current taxonomy title, URL, and more in WordPress.
Creating Taxonomy Archive Templates in WordPress Themes
If you are learning WordPress theme development or making your own custom WordPress theme, then you might want to customize the way your taxonomy pages appear on your website.
This includes pages for categories, tags, and any custom taxonomies.
The good news is that WordPress has a powerful system that allows you to create custom templates for these pages. This means you have a lot of control over how your category and tag pages look on your WordPress website.
WordPress makes this quite straightforward. For example, if you want to create a special template just for your category archive pages, all you need to do is create a file named category.php in your theme’s folder. WordPress will automatically use this file to display your category archive pages, which can help you give your visitors a unique experience when exploring your site.
Similarly, you can create templates for other taxonomies. For a custom taxonomy, you would create a file using a specific format: taxonomy-{taxonomy}-{term}.php. If you’re new to this, you might find our WordPress template hierarchy cheat sheet helpful. It provides a complete overview of all the different types of template files you can use with WordPress.
Once you’ve created your custom taxonomy template file, a good starting point is to copy the code from your theme’s archive.php file. However, you likely want to make changes that are more specific for your taxonomy pages.
For example, you may want to display the taxonomy name in a special location, add a link to the taxonomy RSS feed, or display the taxonomy description or a post count. All of these things can be customized with your own code.
That being said, let’s take a look at how to fetch the taxonomy-related data in WordPress and display it in your WordPress theme.
Showing Taxonomy Title, URL, and More in WordPress
To display all your taxonomy-related data, you need to dynamically find out which taxonomy page is displayed and then get all the required data for that particular taxonomy term.
First, you need to copy and paste the following code into your taxonomy template:
This gets the information of the current taxonomy based on the page you are on.
For example, if you were on a category page called ‘business’, then it will get the information for that taxonomy term.
After that line of code, you can display the title of the taxonomy and other info like this:
echo $term->name; // will show the name
echo $term->taxonomy; // will show the taxonomy
echo $term->slug; // will show taxonomy slug
You can do the same using any of the following values:
term_id
name
slug
term_group
term_taxonomy_id
taxonomy
description
parent
count
filter
meta
Let’s take a look at a real example. In our test child theme, we wanted to display the term title, taxonomy name, number of articles, and the term description.
We used the following code to display this data:
( articles)
You can see we added some CSS classes so we could add custom CSS to style the text, too.
Here is how it looked on our test site:
Expert Guides on WordPress Taxonomies
Now that you know how to show the current taxonomy title, URL, and more in WordPress themes, you may like to see some other guides related to WordPress taxonomies:
We hope this article helped you learn how to show the current taxonomy title, URL, and more in WordPress themes. You may also want to see our cheat sheet for WordPress theme developers or our expert pick of WordPress page builder plugins for no-code solutions.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.