Last active
September 12, 2015 00:46
-
-
Save micjamking/af032a1ccc8a9c34c178 to your computer and use it in GitHub Desktop.
Custom directory location for custom post type templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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