I can create my theme without splitting it into separate files. Why do theme developers split WordPress theme into a few single files like header.php sidebar.php and etc?

3 Answers 3


You need that for child themes. If you have a separate header.php a child theme can use its own header.php and override the parent theme’s file. Plus, header.php and footer.php are used in wp-signup.php.

Another reason is readability: Putting all the code for a theme into just one file gets very messy very fast.

A use case for a compact theme is testing and debugging: My Mini Theme uses just index.php and comments.php for output. Whenever a plugin doesn’t do what I expected I use that theme to be sure it is not a theme issue.


Regardless of the platform (WordPress, Joomla!, Drupal) or the language (PHP, C++, VB) it's pretty much accepted/standard practice to break out code in to functional units. This includes not only functions and classes, but files as well.

As @Toscho points out:

  1. The code is used in multiple places.
  2. It improves readability.

It also makes it easier to:

  1. Maintain your code.
  2. Reuse it in other areas.
  3. Organize it in to manageable chunks/blocks.
  4. Work in a team environment.
  5. ...

The list could go on for a very long time.


Both @toscho's and @stephen's answers good answers, and I upvoted them, but also remember that WordPress looks for particular template files depending upon context. For example, a file named category.php will be used automatically for category archives. author.php will be used for author archives. If you choose not to use the built in template architecture you will have to build those switches (or at least the ones you want) into your code, which would be tedious and redundant.

  • You don’t need any of those switches depending on the styles you are using.
    – fuxia
    Commented Nov 23, 2012 at 22:10
  • It is true that you might not need any of the template hierarchy functionality. That is why I said, "or at least the ones you want".
    – s_ha_dum
    Commented Nov 23, 2012 at 22:16

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.