Programming Goals
-
To make the banner image size smaller to use it for the site logo to allow the site owner to switch it out, if needed.
- The site will eventually have a background image behind the "banner"
- This programming will be called in header.php
Original site - what are the problems?
Example site in process
The "Calling" Code in header.php
Line 1: <?php
Line 2: // Check to see if the header image has been removed
Line 3: $header_image = get_header_image();
Line 4: if ( ! empty( $header_image ) ) :
Line 5: ?>
Line 6: <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
Line 7: <?php
Line 8: // The header image
Line 9: // Check if this is a post or page, if it has a thumbnail, and if it's a big one
Line 10: if ( is_singular() &&
Line 11: has_post_thumbnail( $post->ID ) &&
Line 12: ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) &&
Line 13: $image[1] >= HEADER_IMAGE_WIDTH ) :
Line 14: echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
Line 15: else :
Line 16: ?>
Line 17: <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
Line 18: <?php
Line 19: endif; // end check for featured image or standard header
Line 20: ?>
Line 21: </a>
Line 22: <?php endif; // end check for removed header image
The Code in functions.php
<?php
function YourTheme_setup()
{
// The height and width of your custom header.
// Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 300 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 100 ) );
} // End function YourTheme_setup()
add_action( 'after_setup_theme', 'YourTheme_setup', 9 );
function YourTheme_removeTwentyTenHeaders()
{
unregister_default_headers( array(
'wheel', 'shore', 'trolley', 'pine-cone', 'chessboard', 'lanterns', 'willow', 'hanoi')
);
} // end remove Headers function
add_action( 'after_setup_theme', YourTheme_removeTwentyTenHeaders', 11 );
/* 1/31/12: Added by Nora to have WordPress load the child functions before the parent functions are loaded.
- The 11 means that this will load after the parent theme and change the things we don't want. The parent functions.php file has a value of 10.
*/
?>
This article is based on a discussion topic from the Beyond the WordPress Dashboard course
at The Lifelong Learning Center in Missoula, Montana
Related Articles
- What is "The Loop?"