Taxonomy Terms in Breadcrumbs

How to display the breadcrumbs navigation with hierarchical taxonomies on your website. Tutorial with examples.

#taxonomies  /   10

I think, there are three different options:

  • if the taxonomy isn’t hierarchical,
  • if the taxonomy is hierarchical but only one term of taxonomy could be checked in posts,
  • if the taxonomy is hierarchical and all terms from the tree could be checked in posts.

Non-hierarchical taxonomy

Such taxonomies works like post tags. The simpliest way to print the term links is the_terms() function.

global $post; // this will help if you would use this code inside a custom function
$rd_post_id = $post->ID; // current post ID
$rd_taxonomy = 'region'; // taxonomy name
// the third argument is what you want to add before the navigation, you can leave it empty
// the fourth argument is term link separator , | / •
the_terms( $rd_post_id, $rd_taxonomy, 'Navigation: ', ' / ' );

Taxonomies with hierarchy

These taxonomies works like categories.

1. When only one term is checked

the_terms() functions will work great with this, so, look at the previous code example.

2. When the term tree is checked

This is how it looks:

taxonomy with hierarchy in wordpress admin

In that case the right term order is very important for us.

echo '<div id="kroshki">You are here:';
$rd_taxonomy = 'region'; // region taxonomy
$rd_terms = wp_get_post_terms( $post->ID, $rd_taxonomy, array( "fields" => "ids" ) ); // getting the term IDs
if( $rd_terms ) {
	$term_array = trim( implode( ',', (array) $rd_terms ), ' ,' );
	$neworderterms = get_terms($rd_taxonomy, 'orderby=none&include=' . $term_array );
	foreach( $neworderterms as $orderterm ) {
		echo '<a href="' . get_term_link( $orderterm ) . '">' . $orderterm->name . '</a> &raquo; ';
echo '</div>';

Only the best of WordPress

Subscribe to this weekly newsletter to receive the latest blog posts by email.I respect your privacy. Your email is safe with me.

Comments 10

  • Thank you very much for posting this code! Works a charm.

    How difficult would it be to remove the final part which combines all the terms together i.e. just the terms show?

  • THANK YOU !!! This worked GREAT after looking for HOURS!!

  • Hello, is it possible to show only the one taxonomy term that was clicked? This shows all the taxonomy terms in the taxonomy, not just one.

    • Hello,

      What do you mean by “that was clicked” ?

      • Hello! my taxonomies are set up like this:

        Processing type:
        Type 1
        Type 2
        Type 3

        If I have a post that is tagged with Processing type: Type 1, the “Type 1” links back to its taxonomy page to show other Type 1 posts. I want to show a breadcrumb that indicates that they have clicked on Type 1. But, the code above shows Type 1, Type 2, and Type 3, even though Type 1 was clicked. I would like to show only Type 1 in the breadcrumb :) any ideas?

      • Hi – I figured it out, thanks :)

      • It would be great if you share your solution here 🙃

      • Turns out it was pretty simple, so I’m a bit embarrassed:

        $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); ?>
        <p>You are viewing the following Clinical Type: <?php echo $term->name; ?></p>

Leave your question or feedback

Please, enter a comment
Please, enter a name
Incorrect email