WordPress.org

Ready to get started?Download WordPress

Forums

twenty eleven disable featured image in header (18 posts)

  1. nadjaeberhardt
    Member
    Posted 2 years ago #

    Hi, does anyone know how I can disable the featured image in the header in the twenty twelve theme? It doesn't look like I can remove it from within header settings so is the only option to remove this from within header.php?
    Thanks!

  2. dogoodzilla
    Member
    Posted 2 years ago #

    Create a child theme where you copy header.php from Twenty Eleven. Then you remove the lines from header.php and can still enjoy all the other features in the parent theme. Check theme.fm/2011/07/how-to-create-a-child-theme-based-on-twenty-eleven-791/ for instructions.

  3. nadjaeberhardt
    Member
    Posted 2 years ago #

    Thanks dogoodzilla,
    which lines do I have to remove from the header? I'm not a complete expert at php so sometimes I don't quite get it right!

    <?php
    					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
    					if ( is_singular() && current_theme_supports( 'post-thumbnails' ) &&
    							has_post_thumbnail( $post->ID ) &&
    							( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    							$image[1] >= HEADER_IMAGE_WIDTH ) :
    						// Houston, we have a new header image!
    						echo get_the_post_thumbnail( $post->ID );
    					elseif ( get_header_image() ) : ?>

    But I must've got that wrong as the header wouldn't load anymore...
    Thanks!

  4. dogoodzilla
    Member
    Posted 2 years ago #

    Have you tried disabling the header inage using the setting for it under /wp-admin/themes.php?page=custom-header ?

    I did that for a demo site and it removed the header image from Twenty Eleven. No need to create a child theme, even though child theme is preferred when making custom settings.

  5. nadjaeberhardt
    Member
    Posted 2 years ago #

    I've uploaded a custom header so I can't remove it completely, I just don't want the featured images to override the header... which is why I presume I need to alter the code. Or is there another way you know of?

  6. bluejpro
    Member
    Posted 2 years ago #

    Here's what to do:
    1) create a child theme for twenty-eleven
    2) in the header.php of your child theme, go to line 92 and comment out this line as shown (two slashes in front):
    //echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    3) Now you can add featured images to your posts, and they won't show in your header.

    I second dogoodzilla's suggestion to set up a child theme with a good tutorial like this one at theme.fm

    Hope this helps!

  7. babes44@
    Member
    Posted 2 years ago #

    yes, it works 100%. you super!

  8. lavieoverseas
    Member
    Posted 2 years ago #

    I've tried to remove line 92 from my child theme's header.php as bluejpro noted but when I select a featured image for a post, it STILL shows up as the custom header. I've also tried this and it doesn't work.

    Any help is much appreciated!

  9. rossh_za
    Member
    Posted 2 years ago #

    So more help here please...

    I have followed bluejpro's instructions and they work by removing the featured image, but now there is no header whatsoever.

    How do I edit the header.php to keep the same header static through all pages/posts?

  10. alchymyth
    Forum Moderator
    Posted 2 years ago #

    based on wp3.4 and Twenty Eleven 1.4
    (i.e. will not work in a WordPress version less than wp3.4)

    make sure to create a child theme to work with - http://codex.wordpress.org/Child_Themes

    edit header.php in your child theme, and change the corresponding section to:

    http://pastebin.com/umRMsJuT

  11. rossh_za
    Member
    Posted 2 years ago #

    Thanks so much, works 100%

  12. emaurin
    Member
    Posted 2 years ago #

    Thanks so much, works good in NomNom Child Them 2.0

  13. madisunanne
    Member
    Posted 2 years ago #

    @alchymth,

    I've spent quite a few days finding out how to keep my header static in single-post pages w/o the featured image popping up there. I've tried a bunch of things, & nothing worked except your fix above.

    THANK YOU!

    Blessings,
    madisunanne.
    <3

  14. zink02
    Member
    Posted 2 years ago #

    I found a quicker fix for this problem if anyone is interested.

    In header.php go to line 95 where there is a long if statement to check if the featured thumbnail is big enough to be a header image.

    Simply add a condition into the if statement that is always false.

    I used: && 1==2

    This makes the page think the featured image is never acceptable to be used as a header, so it just keeps your original header image.

  15. hank3
    Member
    Posted 2 years ago #

    @ zink02
    Brilliant!!

  16. nohler
    Member
    Posted 2 years ago #

    I wanted to keep the header so I commented out the if/then condition for the featured image:

    <?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, 'post-thumbnail' );
    			//		else : ?>
    */
    					<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    				<?php // endif; // end check for featured image or standard header ?>
    			</a>
    			<?php endif; // end check for removed header image ?>
  17. chewnibblenosh74
    Member
    Posted 2 years ago #

    So, @zink02, I just tried to do as you suggested and it didn't work. I deleted the && 1==2 and now when I try to access my site, I get an HTML Error 500, Internal Server Error! Help!! (I'm admittedly clueless when it comes to html code. Just starting out...) Can anyone help get me up and running again?? I have no idea what I just did.

    http://chewnibblenosh.com/

  18. erikoliv
    Member
    Posted 1 year ago #

    RESOLVED!

    THIS IS THE ORIGINAL CODE:

    <?php
    				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    				if ( ! empty( $header_image ) ) :
    			?>
    			<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
    				<?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_header_image( $post->ID, 'post-thumbnail' );
    					else : ?>
    					<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    				<?php endif; // end check for featured image or standard header ?>
    			</a>
    			<?php endif; // end check for removed header image ?>

    CHANGE FOR THIS CODE:

    <?php
    // Check to see if the header image has been removed
    $header_image = get_header_image();
    if ( ! empty( $header_image ) ) :
    ?>
    <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    
    </a>
    <?php endif; // end check for removed header image ?>

Topic Closed

This topic has been closed to new replies.

About this Topic