Include a file before current template file
-
I would like to include two files before and after current template. I am using template_redirect to do this,
But when I call get_current_template() inside template_redirect it returns nothing.
is there a way to solve this ??
here is my code:
// current template file add_filter( 'template_include', 'var_template_include', 1000 ); function var_template_include( $t ){ $GLOBALS['current_theme_template'] = basename($t); return $t; } function get_current_template() { if( !isset( $GLOBALS['current_theme_template'] ) ) return false; if( $echo ) echo $GLOBALS['current_theme_template']; else return $GLOBALS['current_theme_template']; } // use template redirect to include file add_action('template_redirect', 'ra_template_block'); function ra_template_block() { include_once THEME_DIR.'/blockstop.php'; get_template_part(get_current_template()); include_once THEME_DIR.'/blocks.php'; exit; }
Way I am doing this
I want to set page layout from a file. I need to include below tags every time in my template file:get_header()
get_footer()
get_sidebar()
get_template_part('right')
get_template_part('left')
So if I can set them from a specific file, then I dont need to include them in every template file.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Include a file before current template file’ is closed to new replies.