Group all page templates/ cpt templates in custom subdfolders
-
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 folderpage-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’ )
- The topic ‘Group all page templates/ cpt templates in custom subdfolders’ is closed to new replies.