Why are the theme files organized like this?


A single file would work but it may well also result is a lot of redundant code being called fir each page load depending in the complexity of the theme.

This page will hopefully explain far better than I can in a forum response:


@mattyrob Thank your for your answer. What redundant code do you mean? Actually the current scheme creates redundancy. You need to load header, sidebar, footer in each template. With the layout > content scheme you only need to load them once – in the layout template. For example:


$template = "index.php"; // or 404.php, archive.php, single.php etc.
include "layout.php";


<!doctype html>
        include $template;

Most of the CMSes and web application frameworks use this scheme, and in my opinion it works better. You can use multiple different layout files when needed, of course.

  • This reply was modified 5 days, 1 hour ago by rzelnik.


Some pages that load in themes don’t need or load the sidebar doe example, so a single file that contains header, content, sidebar, footer, comments etc would load the sidebar code on pages that don’t render it.

Yes, I understand. In this case you can use conditional load or multiple layout templates. The point is that the page layout code is not splitted into two separate files, so it is easier to read.



It is because of the “WordPress way” of hooks, that makes WordPress so flexible. Each template file that is loaded calls an action for that template, so plugins can affect the different parts easily (as well as child themes).
It is much more flexible to build the page in pieces that are shared across pages than to have each page duplicating logic. The content area is not the only place where the theme changes something.

Ok @joyously , thanks for your answer.

Source link