Skip to content

Snippet: Create Unique Sidebar Template Files

/**
 * Display different sidebar templates for your site
 * Requires Total 2.0.3 or greater
 */
function my_wpex_get_sidebar_template( $template ) {

	// Display sidebar-cars.php for your "cars" custom post type
	if ( is_singular( 'cars' ) || is_post_type_archive( 'cars' ) ) {
		$template = 'cars'; // Don't forget to create your sidebar-cars.php file in your child theme
	}

	// Return template
	return $template;

}
add_filter( 'wpex_get_sidebar_template', 'my_wpex_get_sidebar_template' );
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