WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to change the WP default template hierarchy?

For instance;

Say I want to change my theme directory structure so that it completely changes from the Template Hierarchy suggested here based upon conditionals:


If I wanted to make sure that for all page types (is_single() is_home() etc) it always opens one template file which then instigates my own pattern to provide the output?

Thanks very much!

share|improve this question
don't make duplicate questions stackoverflow.com/questions/12196986/… – janw Aug 30 '12 at 13:24
up vote 3 down vote accepted

Try this filter

function wpse_63614_restructure_template_hierarchy( $template ){
    return get_template_directory().'/filename.php';
add_filter( 'template_include', 'wpse_63614_restructure_template_hierarchy' );

The filename would be the file you would want to call in your theme folder. For child themes you would use get_stylesheet_directory instead.


Or as suggested by Chip Bennett and what I too feel would be better; you can use the template_redirect hook in the following manner. The priority can be set accordingly if required.

function wpse_63614_restructure_template_hierarchy(){
    include( get_template_directory().'/filename.php' );
add_action( 'template_redirect', 'wpse_63614_restructure_template_hierarchy' );
share|improve this answer
Thanks Joshua where would this go? In my theme activation? – Alex Aug 30 '12 at 12:53
in your theme's functions.php – Joshua Abenazer Aug 30 '12 at 13:01
This is the right approach, but I would suggest using the template_redirect hook. – Chip Bennett Aug 30 '12 at 13:32
Yup just had a look at the template-loader.php once again. Don't know how did I miss that one. Will add that too in the answer. – Joshua Abenazer Aug 30 '12 at 13:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.