Hello and happy new year

Suppose one has a large theme composed of several post types, page templates and a bunch of custom loops and template parts which is best keeping in separate php files. What's the best practice to organise these files?

For example, suppose I have 10 page templates. How about putting them in a folder named "pages"? And another folder for the archives?

However, how to let Wordpress know where to look for the templates?


2 Answers 2


Page templates are special case and since WP 3.4 can be put in subfolder natively. Other than that WP mostly expects flat file structure for templates.

While template hierarchy is easily adjusted (see dynamic filter in get_query_template(), pretty much only thing needed)... From personal experience - overly extensive and nested directory structure for templates makes developer workflow overly unpleasant very fast.

If you have extreme quantity of templates "how to reduce amount?" is better question than "how to stuff them into folders?".


To further what Rarst stated, named templates can be placed in a subfolder, as can partials (those consumed via get_template_part). In my experience, the built-in templates that WordPress normally looks for, such as header.php, single.php, and home.php, among others, must be located in the template root folder, not a subfolder.

That said, my theme directory structure tends to look like:

  • partials/
    • nav.php
  • templates/
    • custom_named_template.php
  • header.php
  • home.php
  • single.php

(omitted listing all the standard templates for brevity)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.