Skip to content

Instantly share code, notes, and snippets.

@shawnsandy
Last active December 16, 2015 18:59
Show Gist options
  • Save shawnsandy/5481459 to your computer and use it in GitHub Desktop.
Save shawnsandy/5481459 to your computer and use it in GitHub Desktop.
Use custom post types names as templates in WordPress
<?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