Add taxonomy to Genesis breadcrumb

In this example, I’m assuming you’re using BE Events Calendar to add an ‘events’ post type, and have enabled the ‘Event Category’ taxonomy. Add this to your theme’s functions.php file to include the event’s category in the breadcrumb.

You can apply this to any other post type/taxonomy by changing ‘events’ and ‘event-category’ to your post type and taxonomy, respectively.

<?php
/**
* Add Category to Event Breadcrumb
* @author Bill Erickson
* @link http://www.billerickson.net/code/add-taxonomy-to-genesis-breadcrumb
*
* @param string $crumb, current breadcrumb
* @param array $args, the breadcrumb arguments
* @return string $crumb, modified breadcrumb
*/
function be_event_breadcrumb( $crumb, $args ) {
// Only modify the breadcrumb if in the 'events' post type
if( 'events' !== get_post_type() )
return $crumb;
// Grab terms
$terms = get_the_terms( get_the_ID(), 'event-category' );
if( empty( $terms ) || is_wp_error( $terms ) )
return $crumb;
// Only use one term
$term = array_shift( $terms );
// Build the breadcrumb
$crumb = '<a href="' . get_post_type_archive_link( 'events' ) . '">Events</a>' . $args['sep'] . '<a href="' . get_term_link( $term, 'event-category' ) . '">' . $term->name . '</a>' . $args['sep'] . get_the_title();
return $crumb;
}
add_filter( 'genesis_single_crumb', 'be_event_breadcrumb', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk