Skip to content

Instantly share code, notes, and snippets.

@gyrus
Created September 25, 2015 16:58
Show Gist options
  • Save gyrus/023841a0cc548e36419a to your computer and use it in GitHub Desktop.
Save gyrus/023841a0cc548e36419a to your computer and use it in GitHub Desktop.
Re-route template for hierarchical custom post types
<?php
add_filter( 'page_template', 'pilau_hierarchical_cpt_template' );
/**
* Re-route template for hierarchical custom post types
*
* Not sure why this is needed????
*
* @param string $template
* @return string
*/
function pilau_hierarchical_cpt_template( $template ) {
if ( get_post_type() != 'page' ) {
$template = trailingslashit( get_stylesheet_directory() ) . 'single-' . get_post_type() . '.php';
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment