Custom Post Type Archive in Sub Folder

Unlike page templates, WordPress doesn’t look in subdirectories for post template pages. The base function used for locating such templates is locate_template() (see source), which looks in the root directory of your theme (and parent theme).

(On the other hand get_page_templates() searches sub-directory).

You can use template_include filter (which filters the absolute path to your template) to change the template used:

add_filter( 'template_include', 'wpse119820_use_different_template' );
function wpse119820_use_different_template( $template ){

   if( is_post_type_archive( 'entry' ) ){
       //"Entry" Post type archive. Find template in sub-dir. Look in child then parent theme

       if( $_template = locate_template( 'my-sub-dir/archive-entry.php' ) ){
            //Template found, - use that
            $template = $_template;
       }
   }            


   return $template;
}

Leave a Comment