Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Use custom template pages in a WordPress plugin
function my_cpt_templates( $template_path ){
// Change template for CPT single pages
if( is_singular('my_cpt') ){
$template_path = plugin_dir_path( __FILE__ ) . 'templates/single-cpt.php';
}
// Change template for CPT archive pages for a certain taxonomy
if( is_post_type_archive( 'my_cpt' ) ){
$template_path = plugin_dir_path( __FILE__ ) . 'templates/archive-cpt.php';
}
return $template_path;
}
add_filter( 'template_include', 'my_cpt_templates', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment