Organising WordPress Themes – Partial Templates

WordPress

The root directory of your WordPress theme can get pretty crowded pretty fast as a project get steadily more complex. One thing that I found used to frustrate me was differentiating at a glance, my partial template files, from my page template files, from all the others that find their way in there.

De-cluttering your workspace makes it easier to spot items you require at a glance, helping you to avoid losing concentration whilst you’re working.

This becomes especially true when you start collaborating on a project, using task runners and css pre-compilers. All these things can make a theme fairly bulky, so if you know where everything is going to be in advance then it can help to speed up your work process.

Moving Partial Template Files

The easiest modification and usually the first thing I do when modifying or creating a theme from scratch is to separate out my partial template files. Partial templates include header.php, footer.php and perhaps any content.php or loop.php files you may have. Taking all these and moving them to a separate subdirectory where they won’t get in the way.

Retrieving them is as easy as using get_template_part($slug, $name); and prepending the subdirectory path to the $slug argument.

Header and Footer

The header and footer files are often included in theme files by using there own special function get_header(), get_sidebar() and get_footer(). These functions are essentially the same as the get_template_part() function except the $slug argument is not required.

Yes, get_header() and get_footer() are arguably easier to remember and slightly faster to type than get_template_part() but I think the benefits of having a clean organised theme folder outweigh the extra keystrokes.

See Also

Other articles in this series

  1. Organising WordPress Themes – Partial Templates
  2. Organising WordPress Themes – Setting Up a Compass Project

Leave a Reply

Your email address will not be published. Required fields are marked *