The Events Calendar comes with some built-in conditionals that can be very useful when customizing your templates. Recently, a user asked why events were not showing up correctly in his breadcrumbs.

Unless your breadcrumb code is checking for custom taxonomies, it’s not going to know what to do with events and venues. Most breadcrumb plugins use a mix of conditionals to determine what to show, and often custom taxonomies don’t make it into the mix. If you want to show breadcrumbs with events, you’ll need to change that.

To do so, copy the snippet below into your theme’s functions.php file. This code uses our built-in conditionals to handle events and venues.

  • You can use it verbatim- just add tribe_breadcrumbs(); to your page template.
  • If you use a theme framework, add an action hook wherever you want the breadcrumbs to appear: add_action(‘hook_name’,’tribe_breadcrumbs’);

This code is based on the Thesis Breadcrumbs Without Plugins code.

// Check if page is direct child
function is_child( $page_id ) {
	global $post;
	if( is_page() && ($post->post_parent != '') ) {
		return true;
	} else {
		return false;
	}
}

// Breadcrumb Logic
function tribe_breadcrumbs() {
	global $post;

	$separator = " » ";
	
	echo '<div class="tribe-breadcrumbs">';
	echo '<a href="' . get_option('home') . '">' . bloginfo( 'name' ) . '</a>';

	if( tribe_is_month() && !is_tax() ) { // The Main Calendar Page
		echo $separator;
		echo 'The Events Calendar';
	} elseif( tribe_is_month() && is_tax() ) { // Calendar Category Pages
		global $wp_query;
		
		$term_slug = $wp_query->query_vars['tribe_events_cat'];
		$term = get_term_by('slug', $term_slug, 'tribe_events_cat');
		get_term( $term_id, 'tribe_events_cat' );
		$name = $term->name;
		echo $separator;
		echo '<a href="'.tribe_get_events_link().'">Events</a>';
		echo $separator;
		echo $name;
	} elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List
		echo $separator;
		echo 'Events List';
	} elseif( tribe_is_event() && is_single() ) { // Single Events
		echo $separator;
		echo '<a href="'.tribe_get_events_link().'">Events</a>';
		echo $separator;
		the_title();
	} elseif( tribe_is_day() ) { // Single Event Days
		global $wp_query;

		echo $separator;
		echo '<a href="'.tribe_get_events_link().'">Events</a>';
		echo $separator;
		echo 'Events on: ' . date('F j, Y', strtotime( $wp_query->query_vars['eventDate']) );
	} elseif( tribe_is_venue() ) { // Single Venues
		echo $separator;
		echo '<a href="'.tribe_get_events_link().'">Events</a>';
		echo $separator;
		the_title();
	} elseif ( is_category() || is_single() ) {
		echo $separator;
		the_category(' &bull; ');

		if ( is_single() ) {
			echo ' '.$separator.' ';
			the_title();
		}
	} elseif ( is_page() ) {
		if( is_child(get_the_ID()) ) {
			echo $separator;
			echo '<a href="' . get_permalink( $post->post_parent ) . '">' . get_the_title( $post->post_parent ) . '</a>';
			echo $separator;
			echo the_title();
		} else {
			echo $separator;
			echo the_title();
		}
	} elseif (is_search()) {
		echo $separator.'Search Results for... ';
		echo '"<em>';
		echo the_search_query();
		echo '</em>"';
	}
	echo '</div>';
}