1

I'm using add_theme_support( 'custom-header' ) to upload images for an image slider. The slider also has other settings in the customizer (duration, fade, overlay color, etc).

Because there are multiple settings all related to the slider, I'd like to group all of them in the same Customizer panel but I don't see a way to move custom-header into the same panel.

There are settings available but they don't seem to help in this particular case:

$defaults = array(
    'default-image'          => '',
    'width'                  => 0,
    'height'                 => 0,
    'flex-height'            => false,
    'flex-width'             => false,
    'uploads'                => true,
    'random-default'         => false,
    'header-text'            => true,
    'default-text-color'     => '',
    'wp-head-callback'       => '',
    'admin-head-callback'    => '',
    'admin-preview-callback' => '',
);
add_theme_support( 'custom-header', $defaults );

https://codex.wordpress.org/Custom_Headers

So the question is how to customize the location of custom-header in the customizer?

0

1 Answer 1

2

This is kind of a hacky way to accomplish this but digging around core reveals that the default section name is header_image:

https://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/class-wp-customize-control.php#L734

So if we name the section we want it added to as header_image, the custom-header settings will automatically apply to that section. For example:

$wp_customize->add_panel( 
    'example_panel', 
        array(
        'priority' => 10,
        'capability' => 'edit_theme_options',
        'theme_supports' => '',
        'title' => __( 'Example Panel', 'textdomain' ),
        'description' => __( 'Description of what this panel does.', 'textdomain' ),
    ) 
);

$wp_customize->add_section(
    'header_image',
    array(
        'title' => __( 'Slider Images', 'textdomain' ),
        'description' => __( 'This is a section for the slider images.', 'textdomain' ),
        'priority' => 10,
        'panel' => 'example_panel',
    )
);

/* Header Image controls will load here */

The header images controls will display and you can you can continue to add other settings in the panel:

$wp_customize->add_control(
    'example_text',
    array(
        'label' => __( 'Example Text', 'textdomain' ),
        'section' => 'header_image',
        'type' => 'text',
        'panel' => 'example_panel'
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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