0

I've added a theme options page to my site (in my functions.php file):

add_custom_image_header('', 'admin_header_style');

My header.php contains this code, which displays the Featured Image as the banner. If a Featured Image isn't provided it uses the uploaded image banner from the custom image header.

<?php //Custom header
// 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 ), 'post-thumbnail' )) &&
$image[1] >= HEADER_IMAGE_WIDTH ) :
// We have a new header image!
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail', array('usemap' => '#Map') );
else : ?>
<img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>" usemap="#Map" />
<?php endif; ?>

My question is, how can I modify this code to output an h1 text header (i.e. bloginfo('name');) if no banner image has been uploaded (to the site or post)?

2

Try this:

<?php //Custom header
// 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 ), 'post-thumbnail' )) &&
$image[1] >= HEADER_IMAGE_WIDTH ) :
// We have a new header image!
echo get_the_post_thumbnail( $post->ID, 'post-thumbnail', array('usemap' => '#Map') );
elseif ( $img_src = get_header_image () ) : ?>
<img src="<?php header_image(); ?>" alt="<?php bloginfo('name'); ?>" usemap="#Map" />
<?php else: ?>
<h1><?php bloginfo('name'); ?></h1>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.