WordPress.org

Forums

Show Header Image on Front Page Only (14 posts)

  1. peteraloha
    Member
    Posted 1 year ago #

    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

  2. paulwpxp
    Font hero
    Posted 1 year ago #

    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 ?

  3. peteraloha
    Member
    Posted 1 year ago #

    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?

  4. paulwpxp
    Font hero
    Posted 1 year ago #

    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.

  5. peteraloha
    Member
    Posted 1 year ago #

    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; ?>
  6. paulwpxp
    Font hero
    Posted 1 year ago #

    right.

  7. peteraloha
    Member
    Posted 1 year ago #

    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.

  8. paulwpxp
    Font hero
    Posted 1 year ago #

    There should NOT be a <br> tag there.

  9. peteraloha
    Member
    Posted 1 year ago #

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

    Peter

  10. peteraloha
    Member
    Posted 1 year ago #

    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?

  11. paulwpxp
    Font hero
    Posted 1 year ago #

    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' )  ) : ?>
  12. primaveranz
    Member
    Posted 1 year ago #

    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.

  13. WPyogi
    Forum Moderator
    Posted 1 year ago #

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

  14. primaveranz
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic