Support » Themes and Templates » Show Header Image on Front Page Only

  • Alchemyth has already referred to this by proposing this code:

    <?php if( is_home() || is_front_page() ) : ?>
    
    YOUR CODE HERE
    
    <?php endif; ?>

    As newbie, can someone be a bit more granular with instruction: I am using a Child Theme in TwentyTwelve: *Where* specifically do I insert the code above?

    Thank you to anybody that is willing to hold us newbie’s by the hand as we tackle these very basic challenges.

    Peter

Viewing 13 replies - 1 through 13 (of 13 total)
  • Do you have this file header.php in your child theme folder yet ?

    If so, has it been edited ?

    If not, could you make one by copying it over from 2012 theme ?

    Paul: Thanks!
    I have “header.php” in my child theme folder.

    It has been edited but I don’t remember what I changed, HOWEVER, I have not edited it with respect to SHOWING HEADER IMAGE ONLY ON FRONT PAGE.

    Can you guide me from here?

    Look for this block of code. It has 4 lines.

    <?php $header_image = get_header_image();
    
     ( There are 2 lines in this area, just don't touch them )
    
    <?php endif; ?>

    When found, add our code to the top line and the bottom line like this

    <?php if( is_home() || is_front_page() ) : ?>
    <?php $header_image = get_header_image();
    
     ( There are 2 lines in this area, just don't touch them )
    
    <?php endif; ?>
    <?php endif; ?>

    Remember, you are editing a php file live, so you must be very careful and it should go without saying that you should already have a backup, and FTP login just in case if something goes wrong.

    Thanks!
    Just to make sure, this is the code snip, right?

    <?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="" /></a>
    		<?php endif; ?>

    right.

    Here is what I got:

    <?php if( is_home() || is_front_page() ) : ?>
    		<?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="" /></a>
    		<?php endif; ?>
            <?php endif; ?><br>

    NOTE: I moved the
    from the top line <?php endif; ?>

    to the bottom line <?php endif; ?>

    How am I doing? Upload and test?
    By the way, your GUIDANCE is PERFECT!……….thanks for your patience with a beginner.

    There should NOT be a <br> tag there.

    BINGO!…………..Paul: You *ARE* a legend :-)………..great teaching, you are a great teacher, THANKS!

    Peter

    PS: Perhaps my next thread is going to be: How can I insert a CUSTOM HEADER IMAGE on any individual PAGE or POST. Shall I do that in an new post, eh?

    To make header image appear on other pages too, just change this one line

    <?php if( is_home() || is_front_page() ) : ?>

    to the new condition.

    here is the conditional tags that could be used
    http://codex.wordpress.org/Conditional_Tags

    For example, use this to make the header image appear on front page only and also on a page with a slug of about-us too.

    <?php if( is_home() || is_front_page() || is_page( 'about-us' )  ) : ?>

    Have things changed for WordPress 3.8? I can’t see those four lines of code in the Header.php for the TwentyTwelve theme.
    Thanks.

    WPyogi

    (@wpyogi)

    Forum Moderator

    @primaveranz – please start your own thread – this one is outdated and referencing WP3.5.1.

    Please close this one and mark it resolved then. Thanks.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Show Header Image on Front Page Only’ is closed to new replies.