WordPress.org

Support

Support » Themes and Templates » How can I display a different header on Home page and Blog page?

How can I display a different header on Home page and Blog page?

  • Hey, I’ve been trying to display a different header image for my blog versus my static home page via CSS, and then by trying an ‘if’ clause, but no such luck.

    Could someone help me, please?

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

    @esmi

    Forum Moderator

    Have you created a child theme?

    No, only because I am not even sure where to begin to override or manipulate the code that calls the header:

    <?php $header_image = get_header_image();
         if ( ! empty( $header_image ) ) : ?>
    	<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
            <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php bloginfo( 'name' ); ?>" /></a>
         <?php endif; ?>
    esmi

    @esmi

    Forum Moderator

    Do not edit the Twenty Twelve theme. It is will be the default theme in WordPress 3.5 and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes.

    Yes, I understand not editing the theme, but I don’t know what to put in the child theme. I tried using an if statement, something like..

    <?php
    
    if ( is_page( 'blog' ) || '2' == $post->post_parent ) {
        $bannerimg = 'blog.jpg';
    
    } else {
        $bannerimg = 'home.jpg';
    }	
    
    ?>

    ..and CSS..

    <?php if(is_page('Blog')) : ?>class="blog"<?php else : ?>class="home"<?php endif;?>

    ..with..

    .blog { background-image:blog.jpg; }
    .home { background-image:home.jpg }

    ..but where would this be placed when calling the header in the child theme? I tried several different ways, but it hasn’t worked with this theme so far.

    esmi

    @esmi

    Forum Moderator

    where would this be placed when calling the header in the child theme?

    You’d need to start by creating a custom header.php in your child theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How can I display a different header on Home page and Blog page?’ is closed to new replies.