WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
How can I display a different header on Home page and Blog page? (6 posts)

  1. Vanessa
    Member
    Posted 1 year ago #

    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?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Have you created a child theme?

  3. Vanessa
    Member
    Posted 1 year ago #

    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; ?>
  4. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

  5. Vanessa
    Member
    Posted 1 year ago #

    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.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic