• Hi! I want to make a different header for my homepage, I’m using a wp template and I can’t find the code to make it.
    I’m a PHP noobie, so I don’t know what pages I have to change.
    I try to change the code in my index.php page but it doesn’t work
    <?php
    get_header();
    ?>

    to

    <?php if (is_page(index.php)) echo ‘secondary-header’;
    else echo ‘header’;?>

    I have to change also the page.php file ?

    Thanks in advance for any help you can provide!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The correct conditional you want to use for seeing if you’re on the front page is is_front_page(), then you can output different things. You could put this inside header.php itself to control the output. Then it doesn’t matter if you’re home page is the blog page, a page, a page with a custom template, or anything like that because it’ll always be the same header.php.

    Thread Starter vahn00

    (@vahn00)

    In the header.php I have to add it like this ?

    <div class=”header <?php echo (is_page_template(‘page-slider.php’)) ? ‘has-slider’ : ” , echo (is_front_page (‘secondary-header.php’)) ?>”>

    Thread Starter vahn00

    (@vahn00)

    I have tried it and it doesn’t work, now a white stripe appears at the top of my page,
    I’ve make backups and doesn’t disappear

    What are you actually trying to achieve? A different class on the header?

    The code you posted is incorrect PHP. You’re using is_front_page() incorrectly. It doesn’t take any arguments and you’ve put secondary-header.php. What is that for?

    Also, you’ve got quotes in the wrong places and are trying to echo inside a ternary operator.

    @vahn00,
    1) First copy header.php and rename header-front.php.

    2) front-page.php (using this file access site homepage code) – copy page.php and rename with this name.

    3) edit – front-page.php and replace get_header() to get_header(‘front’)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Change the header only on index’ is closed to new replies.