When working with a worpress site with lots of custom post types and lots of page templates, my theme folder is looking messy. What are the accepted best practices to organise code files in WordPress?
a couple of the limitations i’m coming up against are that templates are chosen by name, so i can’t group files by prefixing them. Also custom post template files can not be in sub directories. Also header and footer can not be in subdirectories.
How can i organise my code better?
Not a full answer, but I can at least answer this question:
Everything, that you can load via
get_template_part()
, can reside in a subfolder:It’s as easy as that. Now you’ve your part inside
Slightly off topic.
Then there’re some nice tricks, like using the post format or post type as part name:
In addition to
get_template_part()
being able to specify a subdirectory, page templates (of the variety that have to be selected) can be put into a subdirectory: http://nacin.com/2012/03/29/page-templates-in-subdirectories-new-in-wordpress-3-4/