php - Different header image for each page in Wordpress -
i have wp theme supports custom headers in sense can upload number of header images , randomize them user browses site need each page display single image media gallery related content on page.
i've tried add custom-header.php
if(is_page('about')){ echo '<img src="the-path-to-image/about.jpg" />';
or this
<?php if(is_home) { ?> <?php if( get_header_image() ): ?> <div id="custom-img-header"><img src="the-path-to-image/about.jpg" alt="" /></div> <?php endif; ?> <?php } ?>
but nothing changes ...
code functions.php
require get_template_directory() . '/inc/custom-header.php';
code header.php
<header id="masthead" class="site-header" <?php echo beluga_header_image_background(); ?> role="banner"> <div class="masthead-opacity"></div> <div class="site-branding"> <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>
code custom-header.php
<?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. ?>
can please me , should modify make work ?
you can try using following method banner header:
header.php file
<?php $thumb = get_the_post_thumbnail_url(); if($thumb) { //if image defined $background_set = 'style="background:url('.$thumb.')"'; } else { // if not image defined $background_set = ''; } ?> <header id="masthead" class="site-header" <?php echo $background_set; ?> role="banner"> <div class="masthead-opacity"></div> <div class="site-branding"> <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>
by writing above code can achieve banner image each post. but, remember above code search post thumbnail image page or post , if found output image header banner.
best can create custom image upload meta field displays on posts. upload image there , extract meta content data , output header.php file.
first try above method , reply whether works or not. thanks. !