• Resolved dmx09

    (@dmx09)


    Hi all,

    I wondered if it’s possible to create a duplicate of my header.php, make some minor changes and load the amended header file on certain pages (just the homepage in this instance).. All other pages would load the default header.php.

    So:
    <?php get_header(); ?>
    would load the usual header…

    and:
    <?php get_header_new(); ?>
    would load my tweaked file…

    would this work, or something similar?

    Any advice appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could make an if, something like this

    <?php if( is_page(19) ) {
    echo get_template_part( 'header', 'custom' );}
    else {
    echo get_header(); } ?>

    That way, if the page id is 19 it’ll post the templatefile header-custom.php instead of the usual header. You could substitute is_page()
    with e.g.

    is_page(array(1, 2, 3, 4, ))
    is_home()
    in_category(3)

    And it loads what ever you write, like ding-dong.php would be echo get_template_part( ‘ding’, ‘dong’ );}.
    You can also make elseif’s to have different conditions, if you have multiple headers.

    Havnt tested it out so i dont know if it’s working, but it should.

    Though, if u only make small changes and know which pages the change should be active, you’re easier of by just doing this:
    <?php if( is_page(2) ) { echo "settings for page 2"; } else { echo "settings for all other pages"; } ?>

    Thread Starter dmx09

    (@dmx09)

    That’s excellent, many thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Load different header.php files on different pages?’ is closed to new replies.