Skip to content

Use a Dynamic Template for The Events Calendar Single Events

This snippet relies on a filter from The Events Calendar plugin. If a future version of the plugin changes or removes this filter, the snippet may stop working.

The snippet can be used to override the Tribe Events Calendar single event page with a Total dynamic template.

To use it:

  1. Create a dynamic template under Theme Panel > Dynamic Templates.
  2. Replace $template_id = YOUR_TEMPLATE_ID; in the snippet with your template's ID.
  3. Add elements to your Template to display the event details, such as the Post Content element, the Tribe Event Data element or the Events Calendar shortcodes.
// Loads the theme template for single events instead of the Events Calendar template.
add_filter( 'tribe_events_views_v2_use_wp_template_hierarchy', function( $use_hierarchy ) {
	if ( is_singular( 'tribe_events' ) ) {
		return true;
	}
	return $use_hierarchy;
} );

// Stops the Events Calendar from replacing the single event query with a placeholder page.
add_filter( 'tribe_events_views_v2_should_hijack_page_template', function( $should_hijack, $query ) {
	if ( $query instanceof WP_Query && $query->is_singular( 'tribe_events' ) ) {
		return false;
	}
	return $should_hijack;
}, 10, 2 );

// Uses dynamic template 170 for single events.
add_filter( 'totaltheme/theme_builder/location_template_id', function( $template_id, $location ) {
	if ( 'single' === $location && is_singular( 'tribe_events' ) ) {
		$template_id = YOUR_TEMPLATE_ID;
	}
	return $template_id;
}, 10, 2 );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets
Back To Top