No, you cannot do that, unfortunately, because get_header( $name )
doesn’t have a filter for the $name
(it only passes the name with the action call).
However, if you are willing to modify the header.php
file for each site with something like this right at the beginning of the file:
<?php
if ( apply_filters( 'load_custom_header', false ) ) {
$custom_header = apply_filters( 'get_custom_header', '' );
if ( '' != $custom_header ) {
// Get the header that we just received
// and call the native 'get_header' function
// as usual
get_header( $custom_header );
// By calling 'return' we are skipping
// parsing this template any further
return;
}
}
You can then control what header to load like this (you can either place this code in a plugin or in the functions.php
file):
// We are hooking to the 'load_custom_header' filter
// and return a value of 'true' meaning that we want to
// load a custom header
add_filter( 'load_custom_header', '__return_true', 99 );
add_filter( 'get_custom_header', function( $header ) {
// Figure out what header you want
$some_condition = true;
if ( $some_condition ) {
$header="new";
}
return $header;
}, 99 );
The obvious advantage is that you don’t have to modify all of the get_header
calls from all of the templates: single.php
, page.php
etc. you control all of them in a single place.