Created
May 10, 2013 11:29
-
-
Save charleslouis/5553854 to your computer and use it in GitHub Desktop.
php - wordpress - customp post type - force usage of dedicated template for custom post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*======================================================================= | |
= force dedicated template usage for custom posts = | |
=======================================================================*/ | |
add_filter( 'template_include', 'include_template_function', 1 ); | |
function include_template_function( $template_path ) { | |
if ( get_post_type() == 'fiche-projet' ) { | |
if ( is_single() ) { | |
// checks if the file exists in the theme first, | |
// otherwise serve the file from the plugin | |
if ( $theme_file = locate_template( array ( 'single-fiche-projet.php' ) ) ) { | |
$template_path = $theme_file; | |
} else { | |
$template_path = get_stylesheet_directory_uri() . '/single-fiche-projet.php'; | |
} | |
} | |
} | |
return $template_path; | |
} | |
/*----- End of force dedicated template usage for custom posts ------*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment