WordPress – Custom Taxonomy Breadcrumbs

9:06:00 PM | ,

Copy this to your functions.php file

1<?php
2
3    function postTypeCrumbs($postType, $postTax) {
4
5        $term           = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
6        $taxonomy       = get_taxonomy($term->taxonomy);
7        $parents        = get_ancestors( $term->term_id, $postTax );
8        $parents        = array_reverse($parents);
9        $archive_link   = get_post_type_archive_link( $postType );
10
11        echo '<ul class="ax_crumbs">';
12
13        if ($taxonomy)  {
14            echo '<li><a href="' . $archive_link . '" title="' .$taxonomy->labels->name . '">' . $taxonomy->labels->name . '</a> &raquo; </li>';
15        }
16
17        foreach ( $parents as $parent ) {
18            $p  = get_term( $parent, $postTax );
19            echo '<li><a href="' . get_term_link($p->slug, $postTax) .'" title="' . $p->name . '">' . $p->name . '</a> <span>&raquo;</span> </li>';
20        }
21
22        if ($term) {
23            echo '<li>' . $term->name . '</li>';
24        }
25
26        echo '</ul>';
27
28    }
29?>

Usage

Paste this whereever you would like the taxonomy to display.
1<?php postTypeCrumbs('post type', 'taxonomy name'); ?>