WordPress.org

Ready to get started?Download WordPress

Forums

Tiny Forge
[resolved] Header image only on front page (12 posts)

  1. MaartenBerk
    Member
    Posted 6 months ago #

    Is it possible to have to header image only on the front page? What would be the easiest way?

  2. kaniamea
    Member
    Posted 6 months ago #

    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!

  3. Tomas Mackevicius
    Member
    Theme Author

    Posted 6 months ago #

    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; ?>
  4. MaartenBerk
    Member
    Posted 6 months ago #

    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?

  5. Tomas Mackevicius
    Member
    Theme Author

    Posted 6 months ago #

    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:

    http://codex.wordpress.org/Function_Reference/is_home

  6. MaartenBerk
    Member
    Posted 6 months ago #

    Thanks Tomas,

    Works great!

  7. Tomas Mackevicius
    Member
    Theme Author

    Posted 6 months ago #

    Will wait to see your work ;)

  8. nicolesage
    Member
    Posted 3 months ago #

    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.

  9. Tomas Mackevicius
    Member
    Theme Author

    Posted 3 months ago #

    This was answered in other topic where you asked.

  10. nicolesage
    Member
    Posted 3 months ago #

    Thank you Tomas for helping me on my several questions!!

  11. pcoelho
    Member
    Posted 2 months ago #

    I am using a Tiny Forge theme and i would like to put a hyperlink in header image. How to do?

  12. Tomas Mackevicius
    Member
    Theme Author

    Posted 2 months ago #

    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="" />

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.