I have a group of themes that a client needs consolidated into one. Everything is fairly straight forward, except each theme has theme-specific page templates. Instead of pooling all the template files together in the new master theme, how can I reduce them down to one dynamic template that displays differently depending on a chosen theme option?

When searching myself I came across the template_include filter, which looks like it could be used to override the template that is used, but I'm not sure this is the right solution or how it would be implemented in this case.

Another idea I have would be to just use conditional includes inside the "master" template.

Any suggestions would be much appreciated.

1 Answer 1


Personally, I build everything within index.php of each template. I then do conditional checks.


    // Home page layout
} elseif(is_page()){
    // General page layout
        // Page layout specific to the contact page
    } elseif(is_page('about')){
        // Page layout specific to the about page

Read more on conditional tags.

  • That is considered a bad practice. the Template Hierarchy exists for a reason. Using conditionals like that makes for long, harder to read template files and requires evaluating unnecessary PHP statements. The exact same templates could be created with front-page.php, page.php page-contact.php and page-about.php, respectively.
    – mrwweb
    May 22, 2012 at 3:08
  • 1
    @mrwweb Both approaches are valid and may be appropriate in certain cases (that's why these conditionals exist). Please do not try to give the impression that your preference is generally accepted and always to be followed.
    – fuxia
    May 22, 2012 at 3:27
  • 1
    Maybe I worded this too strongly, but I did go to the Codex to double-check what I thought I had read before. "If your Theme needs to have even more control over which Template files are used than what is provided in the Template Hierarchy, you can use Conditional Tags." That strikes me as a best practice recommendation. I see that it's not a Theme Review Requirement, but it is a recommendation. I'm not arguing against all conditional tags, just ones that replace the template hierarchy.
    – mrwweb
    May 22, 2012 at 3:40
  • In the end, I didn't really need to get tricky with page templates at all. All of the themes being consolidated were variations on the same layout, so the framework between them was essentially the same - not much needed to be tweaked for it to work. Great comments! Jul 4, 2012 at 21:12

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.