Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#53676 closed defect (bug) (invalid)

Default Custom Header image is not staying active

Reported by: andre-jutras's profile Andre Jutras Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.7.2
Component: Themes Keywords:
Focuses: Cc:

Description

I remember this once long ago but cannot remember the issue. Working on a theme and noticed that when there are no additional images uploaded to the Header Image via the customizer, and when "hiding" the default header image, then reselecting the default one, click Save and then refresh, it does not stay active. I tried this by adding the header support in the Twenty Twenty One theme, nope, doesn't work there either.

I tried this in WP 5.7.2 and also 5.8 RC3

Test Code to add support to the 2021 theme function file:

// Setup the WordPress core custom header image.  
add_theme_support( 'custom-header', array( 
  'width'         => 1920,
  'height'        => 800,
  'flex-height'   => true,
  'flex-width'    => true,
  'default-image' => get_template_directory_uri() . '/assets/images/header.jpg',
  'uploads'       => true,
) );

Then, to add it to the header.php template:

<?php if ( get_header_image() ) : ?>
    <img src="<?php header_image(); ?>">
<?php endif; ?>

Head over to the customizer's Header Image tab and make sure no added images exist, except the default one.

  1. Make sure the default header is not active
  2. Select the default (suggested) header and save
  3. Refresh the full customizer window
  4. The default image shows as a thumbnail but is no longer active and is now Suggested.

Even if I upload additional images, try them out, they work, however, if I once again select the default header image, it's a no-go on it.

Change History (2)

#1 @Andre Jutras
4 years ago

I think I found the issue...default custom header image(s) need to have them registered, in addition to

add_theme_support( 'custom-header' );

So far, it seems to have solved it.

#2 @desrosj
4 years ago

  • Component changed from Customize to Themes
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi @andre-jutras,

Thanks for this ticket! You are correct, default headers need to also be registered. Glad you were able to figure this out.

Note: See TracTickets for help on using tickets.