The theme system in WordPress is one of its great strengths and something that is loved by most WP users. It’s a very good thing. However, different developers like setting up code in different ways.
While the theme system works well as advertised, it doesn’t work exactly the way I like to set up my web front-end code. Luckily, it is so flexible that I can easily implement my preferred system.
The standard theme set-up has a header file, footer file, sidebar file and index, single and page files that include the header, footer and sidebar. This is all well and good, but if you make a change to your overall layout, you often have to make it in 3 places (the index, single and page files).
I prefer a template approach, where I have a master template that has a few
I’ve set up my master template, with the holes and display logic I need to keep the site consistent and only have to make changes in one place. This contains the code that would normally be in the header file, the footer file an some of the index, page, single and sidebar files.
In the index, page, single and sidebar files, I buffer the output into variables instead of spitting the content out directly. Then at the end of each template file, I include my master template, which places each variable nicely into it’s home in the template and outputs the page.
This allows the template system to follow the theme convention of having different pages, while allowing me to control the master site code in a single place.
If you’re tired of editing several files when you want to make a change that (for example) affects both your “page” templage and your “single” template, you may want to consider this approach.