Last active
December 16, 2015 18:59
-
-
Save shawnsandy/5481459 to your computer and use it in GitHub Desktop.
Use custom post types names as templates in WordPress
This file contains hidden or 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 | |
/** | |
* | |
* @link Blog post info and description | |
*/ | |
function post_type_templates($template) { | |
/** access gobal */ | |
global $post; | |
/** get the post type */ | |
$post_type = get_post_type($post->ID); | |
/** if post type archive template name is post_type */ | |
if (is_post_type_archive()) { | |
/** check for the template else use default */ | |
$located = locate_template(array($post_type.'.php')); | |
if(!empty($located)) | |
$template = get_query_template($post_type); | |
} | |
return $template; | |
} | |
add_action('template_include', 'post_type_templates'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment