Skip to content

Instantly share code, notes, and snippets.

@timothyjensen
Last active June 4, 2019 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothyjensen/5de0095eebb6bdd8ca425211c7273fcb to your computer and use it in GitHub Desktop.
Save timothyjensen/5de0095eebb6bdd8ca425211c7273fcb to your computer and use it in GitHub Desktop.
<?php
add_filter( 'template_include', 'your_custom_cpt_template', 99 );
/**
* Load an alternative template file for a given post type
*
* @param string $template path to the default template
* @return string $template path to the default template
* @return string $custom_template path to the custom template
*/
function your_custom_cpt_template( $template ) {
if ( ! is_singular( array( 'your_cpt_1', 'your_cpt_2' ) ) ) { // Change 'your_cpt_x' to the slug of your custom post type(s)
return $template;
}
$custom_template = locate_template( array( 'your_cpt_template.php') ); // Change 'your_cpt_template.php' to the file name of your template (e.g., 'page_landing.php')
if ( ! $custom_template ) {
return $template;
}
return $custom_template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment