Your code is correct, and the default-image is in fact removed from the related PHP global value. The reason you still see the default image in the customizer is the JS is picking up the image from localized script. It’s not clear to me how it’s getting there. A reasonable workaround IMO would be to simply hide the image button with CSS
.header-view:first-child {
display: none;
}
Provided you add another suggested image, even if someone were to pick the randomize suggested headers option, the default will not rotate in because it’s missing in the PHP global data.
@bcworkz
Thanks for your reply!
Thanks for confirming my code and supplying a suggestion.
It’s a mystery to me that no one has raised this question before… TwentySeventeen being a deafult theme…
Finally got your workaround to work. Had to put the CSS within the action hook
customize_controls_print_styles
Again, thanks!
Hi,
Did either of you find out why this is happening? I don’t want to use the work around and I’m tearing my hair out trying to get to the bottom of it!
Thanks,
Oliver
I think the problem is here in WordPress core theme.php …
// Merge in data from previous add_theme_support() calls.
// The first value registered wins. (A child theme is set up first.)
if ( isset( $_wp_theme_features['custom-header'] ) )
$args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] );
It appears to include any previously set values!
Any ideas?
Oliver
OK, I solved it.
You have to tackle the custom header and default image separately. One before Twenty Seventeen and one after.
function new_twentyseventeen_default_image_setup() {
register_default_headers(
array(
'default-image' => array(
'url' => plugin_dir_url( __FILE__ ) . 'images/header.jpg',
'thumbnail_url' => plugin_dir_url( __FILE__ ) . 'images/header.jpg',
'description' => __( 'Default Header Image', 'twentyseventeen' ),
),
)
);
}
function new_twentyseventeen_custom_header_setup() {
add_theme_support(
'custom-header', apply_filters(
'twentyseventeen_custom_header_args', array(
'default-image' => plugin_dir_url( __FILE__ ) . 'images/header.jpg',
'width' => 2000,
'height' => 1200,
'flex-height' => true,
'video' => true,
'wp-head-callback' => 'twentyseventeen_header_style',
)
)
);
}
add_action('after_setup_theme', new_twentyseventeen_custom_header_setup', 9);
add_action('after_setup_theme', 'new_twentyseventeen_default_image_setup', 11);
Hope this helps someone else.
I don’t give up 🙂
Oliver