0

I have issues with putting my own default custom-header image for my child theme, but am unable to do so without altering the parent theme (twenty seventeen).

I'm able to remove the custom header with:

remove_theme_support('custom-header', 15);

But when I add them back in my child theme, the child theme still shows the twenty seventeen default custom-header image

$custom_header_args = array(
        'default-image'      => get_theme_file_uri( '/assets/images/header.jpg' ),
        'width'              => 2000,
        'height'             => 1200,
        'flex-height'        => true,
        'video'              => true,
    );
    add_theme_support( 'custom-header', $custom_header_args );

This is maybe best demonstrated with the minor modifications in the twenty seventeen /inc/custom-header.php file.

    add_theme_support( 'custom-header', apply_filters( 'twentyseventeen_custom_header_args', array(
        'default-image'      => get_parent_theme_file_uri( '/assets/images/header.jpg' ),
        'width'              => 2000,
        'height'             => 1200,
        'flex-height'        => true,
        'video'              => true,
        'wp-head-callback'   => 'twentyseventeen_header_style',
    ) ) );
    remove_theme_support('custom-header');
    add_theme_support( 'custom-header', apply_filters( 'twentyseventeen_custom_header_args', array(
        'default-image'      => get_theme_file_uri( '/assets/images/header.jpg' ),
        'width'              => 2000,
        'height'             => 1200,
        'flex-height'        => true,
        'video'              => true,
        'wp-head-callback'   => 'twentyseventeen_header_style',
    ) ) );

If I have it like this, the parent theme's header.jpg is shown as the custom header. However, if I comment out the first default-image definition, I see the child theme header.jpg.

So why are the previous values not overwritten? How are they even supposed to be overwritten?

0

No need to do the remove_theme_support, just put yours in your functions.php file, make sure its a different image (might sound obvious but just in case):

$custom_header_args = array(
    'default-image' => get_theme_file_uri( '/assets/images/header.jpg' ),
    'width' => 2000,
    'height' => 1200,
    'flex-height' => true,
    'video' => true,
);
add_theme_support('custom-header', $custom_header_args);

the child theme custom header theme_support values will always override the values of the parent, its commented in the core:

// 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] );

the functions.php of the child theme will run first (registering the theme support first) then the functions.php of the parent.

  • Thank you! This solved the problem. I thought that I had tried this in the beginning but apparently I had something wrong there also :P – Pingviinituutti Feb 22 '17 at 20:42

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.