Is there a way to automatically run get_header()
at the beginning of template and get_footer()
at the end of it?
Currently my code is too repetitive with those calls.
I’ve been looking for a way to do this, but I can’t find it in Google.
Is there a way to automatically run get_header()
at the beginning of template and get_footer()
at the end of it?
Currently my code is too repetitive with those calls.
I’ve been looking for a way to do this, but I can’t find it in Google.
Looking at wp-includes/template-loader.php
… there seems to be a way:
if ( $template = apply_filters( 'template_include', $template ) )
include( $template );
You could hook into that filter, handle the including in a callback function and return FALSE
.
Sample code, not tested:
add_filter( 'template_include', function( $template ) {
get_header();
include $template;
get_footer();
return FALSE;
});