Since The Events Calendar plugin does not use the default WordPress pages hierarchy and related taxonomies, it may totally break your Yoast SEO breadcrumbs.

Fortunately, Yoast SEO provide some helpful hook to let us add our own rules. The following function fix the breadcrumbs on events pages and events archive page.

function bweb_events_wpseo_breadcrumb_output( $output ){
	if( is_singular( 'tribe_events' ) ){
		$queried_object = get_queried_object();
		$obj = get_post_type_object( 'tribe_events' );
		$from = '';
		$to = ' » ' . $obj->labels->name . '';
		$to .= ' » '. $queried_object->post_title .'';
		$output = str_replace( $from, $to, $output );
	}
	if( is_post_type_archive( 'tribe_events' ) ){
		$queried_object = get_queried_object();
		$from = $queried_object->label;
		$to = $queried_object->labels->name;
		$output = str_replace( $from, $to, $output );
	}
	return $output;
}
add_filter( 'wpseo_breadcrumb_output', 'bweb_events_wpseo_breadcrumb_output' );

 

Please note that the function will only work if you use the default separator “»” in the Yoast breadcrumbs settings. If you change it, you have to edit the function in consequence.

 

Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post

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