0

I am trying to change the header template using the get_header action but it wont change anyway I try to do it.

Here is what I tried by adding this in functions.php:

function prefix_new_header() {
    return 'newtmpl';
}
add_action( 'get_header', 'prefix_new_header' );

I have in the theme folder a file called header-newtmpl.php

I’ve tried different priorities (1, 10, 99), but it doesn’t work.

Is there something I am missing? Thanks for any help!

You can try this in twentysixteen, if you want to test it.

1

1 Answer 1

1

You can use a conditional logic. E.G.

<?php
if ( is_home() ) :
    get_header( 'home' );
elseif ( is_404() ) :
    get_header( '404' );
else :
    get_header();
endif;
?>

The file names for the home and 404 headers should be header-home.php and header-404.php respectively.

So in your page-template just add

        get_header( 'newtmpl' );

dunno why you should use a function for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.