<?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