Skip to content

Instantly share code, notes, and snippets.

@micjamking
Last active September 12, 2015 00:46
Show Gist options
  • Save micjamking/af032a1ccc8a9c34c178 to your computer and use it in GitHub Desktop.
Save micjamking/af032a1ccc8a9c34c178 to your computer and use it in GitHub Desktop.
Custom directory location for custom post type templates
<?php
// Selects Custom Post Type Templates for single and archive pages
// ----------------------------------------------------------------------
add_filter('template_include', 'custom_template_include');
function custom_template_include($template) {
$custom_template_location = get_stylesheet_directory() . '/my-inc/my-templates/';
if ( get_post_type () ) {
if ( is_archive() ) :
if( file_exists( $custom_template_location . 'archive-' . get_post_type() . '.php' ))
return $custom_template_location . 'archive-' . get_post_type() . '.php';
endif;
if ( is_single() ) :
if(file_exists( $custom_template_location . 'single-' . get_post_type() . '.php' ))
return $custom_template_location . 'single-' . get_post_type() . '.php';
endif;
}
return $template;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment