Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active November 4, 2015 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/5c382c95e356064db308 to your computer and use it in GitHub Desktop.
Save billerickson/5c382c95e356064db308 to your computer and use it in GitHub Desktop.
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment