template_include
filter is for template files, header.php is a template part. That is why template_include
doesn’t work for it. As I said, looking at the source code of get_header()
function, I can not see any way you can override the loaded file by that function (or any other template part). But, because it is a template part, you are not requiered to use it. You can define the full header section into a template file or include any file you may want as header.
For example, a template file loaded from the plugin folder could be like this:
<!doctype html>
<html <?php language_attributes();?>>
<head>
<?php wp_head(); ?>
</head>
<body id="body" <?php body_class(); ?>>
<?php if ( have_posts() ) { ?>
<?php while ( have_posts() ) { the_post(); ?>
<?php } ?>
<?php } ?>
</body>
</html>
As you can see, I’ve also not used get_footer()
; like get_header() and header.php, footer.php is a template part and you are not required to use it.
Also, to not repeat same code in all your template files, you could include the header and footer parts using PHP include()
function:
<?php include('myheader.php'); ?>
<?php if ( have_posts() ) { ?>
<?php while ( have_posts() ) { the_post(); ?>
<?php } ?>
<?php } ?>
<?php include('myfooter.php'); ?>