Header image for template specific page only

Hi all - my site currently displays header_image on all pages when I’d like it to just be template specific (home-page.php).

The code below is called in the header.php

<header id="masthead" class="site-header" role="banner">
	<div class="site-branding col-width">
		<?php if ( get_header_image() ) : ?>
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
				<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
			</a>
		<?php endif; // End header image check. ?>
		<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
		<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
	</div>
</header><!-- #masthead -->

<?php if ( is_page_template('templates/home-page.php') ) {
	get_template_part( 'templates/above', 'home-page' );
} ?>

Sorry I’m a little confused, you should be able to just move that if statement up. Something like:

<?php if ( is_page_template('templates/home-page.php') ): ?>
	<header id="masthead" class="site-header" role="banner">
		<div class="site-branding col-width">
			<?php if ( get_header_image() ) : ?>
				<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
					<img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
				</a>
			<?php endif; // End header image check. ?>
			<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
			<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
		</div>
	</header><!-- #masthead -->
<?php endif; ?>
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.