Header image only on front page
-
Is it possible to have to header image only on the front page? What would be the easiest way?
-
Hi MaartenBerk,
you can certainly have different headers. The way you do that is in 4 easy steps:1) Create a child theme – http://codex.wordpress.org/Child_Themes
2) Copy your header.php file into your child theme and rename it to header-home.php
3) From your new header-home.php remove this code:<?php // The header image // Check if this is a post or page, if it has a thumbnail, and if it's a big one if ( is_singular() && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) && $image[1] >= $header_image_width ) : // Houston, we have a new header image! echo get_the_post_thumbnail( $post->ID, 'custom-header-image' ); else : if ( function_exists( 'get_custom_header' ) ) { $header_image_width = get_custom_header()->width; $header_image_height = get_custom_header()->height; } ?> <?php // Check to see if the header image has been removed. if ( ! empty( $header_image ) ) : ?> <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="" /> <?php endif; // end check for removed header image ?> <?php endif; // end check for featured image or standard header ?>
4) Add your index.php file to your child theme and rename get_header(); located at the beginning of the page to get_header( home );
Hope this helps!
Hi, kaniamea,
your solution would render home page without header, but Maarten asked the oposite. For the task to complete I would just copy the header.php and wrap the header image section in:
<?php if ( is_home() ) : ?> header image code goes here... <?php endif; ?>
Thanks for answering,
I’m trying to create an child theme, but I’ve got problems with creating directory’s, I’m figuring out why at the moment.
I’ve got a question about is_home
I deleted the home page and set up a new page which is my front page now.Does that effects anything? Should I use the name of the page instead?
If it is a page you have to use:
is_front_page()
http://codex.wordpress.org/Function_Reference/is_front_page
is_home
on the other hand checks if it is a page, where you display your posts, usually it is index page, where people display the wall of latest posts, but not in the custom page scenario:Thanks Tomas,
Works great!
Will wait to see your work 😉
Hi. Wonderful theme. I will have an example to show soon of how I’m using your theme.
I wanted to know if you could confirm where exactly the code gets placed in the header.php file. I’m having trouble figuring it out. My home page that I would like to heave the header image is using the Front Page Template. The other pages are using Full Page Template, No Side bars. I would like to remove the header image, as well as the ‘leave a replay/comments box’ from these pages. So I assume its removing something from another .php file, just unsure which one.
Thank you so much, I have never worked with a theme that offered such support. It truly is great for a beginner who wants to learn.
This was answered in other topic where you asked.
Thank you Tomas for helping me on my several questions!!
I am using a Tiny Forge theme and i would like to put a hyperlink in header image. How to do?
Try to enclose in a link this header.php code:
<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="" />
- The topic ‘Header image only on front page’ is closed to new replies.