Skip to content

Snippet: Define Your Dynamic Post Template via Code

While you can already define your dynamic post template for posts, portfolio, staff, testimonials via the Customizer and you can define it for custom post types when using the Post Types Unlimited Plugin, if you are creating new post types via another method than you would define your dynamic template via some code added to your child theme using the "wpex_get_singular_template_id" filter.

// Define custom singular template ID's
// Note: your template can be any post type and it supports templatera and elementor templates
add_filter( 'wpex_singular_template_id', function( $template_id ) {
	if ( is_singular( 'doctors' ) ) {
		return 4; // Change this to the ID of your template
	}
	return $template_id;
} );
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)
Back To Top