Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charleslouis/5553854 to your computer and use it in GitHub Desktop.
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
/*=======================================================================
= 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