Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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)?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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; ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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