• Hi there,

    How can we remove the header image on all pages EXCEPT the home page?

    What code do I use to do this, and where do I place it in the child theme?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Were you able to find a solution?

    Hi, try this in the header.php where the div “header-image” starts somewhere at line 91:

    <?php if ( is_home() ) {// This is the blog posts index
    				<div class="header-image">
    					<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
    						<img src="<?php header_image(); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_custom_header()->attachment_id ) ); ?>" sizes="<?php echo esc_attr( $custom_header_sizes ); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
    					</a>
    				</div><!-- .header-image -->} 
    ?>
    • This reply was modified 7 years, 7 months ago by Marco77.

    Maybe this is better, at line 78 at the code:

    <?php if ( get_header_image() ) : ?>

    replace it by:

    <?php if ( is_home() ) { get_header_image() } ?>

    Tried this. Broke the website. Better solution?

    Hi there, I am a novice at WP but I have built two sites in three years and struggled each time and the first one crashed and burned with the WP upgrade last fall. I did a lot of research and I give credit to those that will help someone that is new to WP.

    After doing my research and asking several times how to remove all of the images from every page except my Home page in Theme Twenty Sixteen, I never got any response. I kept looking and researching and I finally ran across a blog and I guy asked the same question and I guy replied back with the longest line of code that I have yet to see and said this should resolve your problem. I copied and pasted the code and it eliminated every Image which are large 1280 x 280 on every page except the Home page in Theme 2016.

    I am not sure which Theme you are using but from my experience with removing the Images in 2016 I believe it will take more than what I have seen. Again, I am a novice but I turned Theme 2016 into a website, but I can tell you that working anywhere in the Header Area you are going to get some wrap-around issues no one could answer or would not answer. My suggestion is just keep searching and reading and you might just come across what you need. If it took the line of code that I had to use then I would think you will be faced with the same issue.

    Marco77 was on to the right idea.

    header.php (i.e. wp-content/themes/twenty-sixteen/header.php) line 78:

    <?php if ( get_header_image() ) : ?>

    add && is_front_page()

    so,

    <?php if ( get_header_image() && is_front_page() ) : ?>

    should do the trick

    In my theme, there is no

    <?php if ( get_header_image() ) : ?>

    So I don’t know where to make the change.

    I use the Landscape theme by Diverse themes.

    Works for me in my case:
    <?php get_template_part( ‘template-parts/header/header’, ‘image’ ); ?>
    Change to
    <?php if ( is_front_page() ) {get_template_part( ‘template-parts/header/header’, ‘image’ );} ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘HOW TO only display header image on homepage’ is closed to new replies.