get_header and hook avoid normal call

I would like to use a custom header, like get_header('new')

But I cannot modify the templates easily where the calls are being made due to several reasons. (many files and same code base deployed on several different domains where some domains must not load the new header and use the same templates, so i want to load the new header on one place with a condition based on domain)

Is there any way I could make a hook and call the header function with the parameter myself, but then NOT calling the usual default call?

function new_get_header(){
    //die or something
add_action('get_header', 'new_get_header');

Any tips appreciated.

Solutions Collecting From Web of "get_header and hook avoid normal call"

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:

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        

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.