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!


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' );
  • 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
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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