• I’m trying to undesrdtand how to group all my custom post types templates in a subfolder and same for my page templates.
    I saw that wp allow and recognize the creation of the folder page-templates for group the page templates but i could not find a similar way for the cpt templates.

    Here is a way for group them in a folder with a custom name without slowing to much wp?

    I read on some posts in WordPress Development ( 2013 answer so since then maybe something has changed ) that you can achieve something similare by creating a function like this

     
    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;
    }
    

    but as i can see it seems that you should define this for every cpt created, and i read also that this can slow a bit wordpress becouse it will search in that folder as at the last attempt to find the file.

    Here is a faster way ? ( Maybe also for page templates, i would like a custom folder name instead of ‘page-templates’ )

    • This topic was modified 3 years, 11 months ago by linch1.
    • This topic was modified 3 years, 11 months ago by linch1.
Viewing 1 replies (of 1 total)
  • Your question indicates that the custom post types are known by the theme. This is bad practice since it locks you into using that theme. Custom post types should be in plugins, and the plugin provides the template or filters the_content so that the theme remains generic.

Viewing 1 replies (of 1 total)
  • The topic ‘Group all page templates/ cpt templates in custom subdfolders’ is closed to new replies.