Skip to content

Instantly share code, notes, and snippets.

@priscillamc
Created March 30, 2015 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priscillamc/9fd2f5fdc1827fe39a3a to your computer and use it in GitHub Desktop.
Save priscillamc/9fd2f5fdc1827fe39a3a to your computer and use it in GitHub Desktop.
// 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