How to Insert Taxonomy Terms in Breadcrumbs

There are plugin available for this and also this basic feature in few theme and seo plugin. But insert of custom Taxonomy Terms in Breadcrumbs is little hard. So you can get result this from this code.

Non-hierarchical taxonomy in Breadcrumbs

Such taxonomies works just 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 = 'location'; // taxonomy name
// the 3rd 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 for Breadcrumbs

Please note and be very careful: In that case the right term order is very important for us.

echo '<div id="nameabc">You are here:';
$rd_taxonomy = 'location'; // location 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> » ';
	}
}
the_title();
echo '</div>';

Leave a Comment

Your email address will not be published. Required fields are marked *