Displaying A Different Header Image On Homepage Than Other Pages

There’s several different ways you can display one header image on the homepage and another on all other pages.

  1. You can use php code with a conditional tag in the Genesis Simple Hooks plugin.
  2. You can write a custom function which includes a conditional tag.
  3. And you can use CSS code to get the job done as well which may be the best option for you depending on your needs.

Lets take a look at using PHP code and then we’ll look at how to use CSS code to get the job done.

PHP Custom Function

This is a better way to do it in my opinion if you want to use PHP code:

function specific_header_image(){
    if(is_home())
    echo '<div class="home-header"><img src="http://example.com/path/to/image.png" alt="home header image" /></div>';
    elseif(is_page() )
        echo '<div class="page-header"><img src="http://example.com/path/to/image.png" alt="page header image" /></div>';
}
add_action('genesis_header', 'specific_header_image');

The only problem is, you will also need to tweak your CSS to make your images look their best. You can do this using the 2 classes generated by the above PHP code.

Using CSS To Display Different Header Image Sizes On Specific Pages

One the reasons you may choose to use CSS rather than PHP is the fact you’ll need to unhook the genesis_header in Simple hooks otherwise you’ll find both headers displaying on the same page.

When you unhook the genesis_header hook, you also disable the header right widget which may not be ideal especially if you use it to display something.

Simple modify this code and add it to the end of your child themes style.css file.

.home .site-header {
 height: 262px;
 background: url("images/big.png") no-repeat scroll 0 0 transparent;
 }
 
 .site-header {
 max-width: 980px;
 margin: 0 auto;
 width: 100%;
 height: 149px;
 background: url("images/small.png") no-repeat scroll 0 0 transparent;
 }

Change the images/big.png and small.png to the full url to your different header images.

You can grab this from your WordPress media library.

The above code displays a unique header image on the home page whereas all other pages display a smaller header image.

But what if i want more than 2 header images to display on different pages, posts and archives?

What if the header images are all different heights?

You’ll need to use the body class or create custom classes for this.

Here’s another method which is the best in my opinion.

The Best Solution With CSS

Simply remove the PHP code from your child themes functions.php which adds support for a custom header to your theme:

/** Add support for custom header */
add_theme_support( 'genesis-custom-header', array(
	'width' => 960,
	'height' => 120
) );

Removing this code will NOT effect the header right widget.

Then add this CSS code to the end of your child themes style.css file.

.site-header {
background: url("images/home-header.png") no-repeat scroll 0 0 transparent;
height: 300px;
}

.page-template-default .site-header {
background: url("images/page-header.png") no-repeat scroll 0 0 transparent;
height: 120px;
}

Here’s some working CSS examples that work based on different scenarios.

No need to unhook the header or do anything else if using this code.

Simply upload 2 images to your child themes images folder named page-header and home-header. Both should be the same width and you can easily modify the height in the above codes CSS which should match the actual height of each header image.

Plugin for Displaying Headers On Specific Pages

The WP Display Header plugin enables you to display specific header images on posts, pages, custom posts types and archives pages.

Related Tutorials


Comments

8 responses to “Displaying A Different Header Image On Homepage Than Other Pages”

  1. hi–

    now that i’ve figured out how to have a different logo on just my homepage, im curious to know how i can change the behavior of that logo. currently it stays in the same place when i scroll down, though im wondering how i can change it so that it scrolls up with the rest of the image, but again, only on the homepage?

    thanks so much for all these hints, it really makes customization so much more encouraging!
    emily

  2. Rosendo Cuyasen Avatar
    Rosendo Cuyasen

    Cool! did you have a chance to developed a header that would hide some other function in the header if you are into mobile mode. Hope that you could also share information about it.

    1. Brad Dalton Avatar
      Brad Dalton

      You could use a mobile conditional tag for this. http://wpsites.net/web-design/conditional-tags-mobile-devices/

  3. Hi Brad,

    I’m building a website in the Genesis Lifestyle theme; we need to display different headers on different pages. I couldn’t get the WP Display Header plugin to work; it still displays the default header image no matter which one is selected. Is there some edit we need to be doing to the theme before the plugin will work with it? I’m stumped!

    Thanks so much.
    Denise

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Denise

      I just tested it on the Lifestyle Pro theme and it worked for me.

      Maybe the plugin author might know what the problem is otherwise it could be another plugin conflicting

      1. Hi Brad,

        Wow! Thanks for your reply – that was fast.

        I think there may be a conflict with another plugin; this particular site is small but needs some specialized functionality so we’re using a number of them.

        Thanks again! Your website is such a great learning resource.

        cheers –
        Denise

  4. Hi Brad
    I need some help! I have designed a website as a complete beginner and used Artisteer to do the template (about 3 years ago) I now need to modernize it and propose to use the Associate theme from studio Press. I have downloaded the theme and the Genesis framework and installed (but not activated)
    When I preview the theme it shows my home page but no place for the slider header image. Basically I have no idea what to do next (have backed up the site) Do you do consultancy? I may need more than a comment or two! Many thanks for any ideas

    1. Brad Dalton Avatar
      Brad Dalton

      Hi Sue. Yes i’m an expert with Genesis child themes and do actually offer a free migration and setup setup, (conditions apply) otherwise i would be happy to do some work for you if you put together a list of what you need done.

      You’ve chosen wisely with Genesis..

      Please send me a direct message if you need further clarification.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.