0

I'm using Underscores to build a theme and I've added an image selector to the customization section, which appears just like the default Background Image section, except clicking 'Select Image' doesn't bring up the media library for some reason. Here's the code I'm using:

function hi_customization_options( $wp_customize ) {
    $wp_customize->add_section(
        'landing_page_image',
        array(
            'title' => 'Landing Page Image',
            'priority' => 35,
        )
    );

    $wp_customize->add_setting(
        'lp-image_selector',
        array(
            'default' => '',
        )
    );

    $wp_customize->add_control(
        'lp-image_selector',
        array(
            'label' => 'Landing Page Image',
            'section' => 'landing_page_image',
            'type' => 'image',
        )
    );
}
add_action( 'customize_register', 'hi_customization_options' );

Presumably I need to add a 'choices' array to the add_control section, but I'm not sure how to target the media library?

Thanks

1

I figured this out. For anyone facing the same issue, I ended up using this code instead:

function hi_customization_options( $wp_customize ) {
    $wp_customize->add_section(
        'landing_page_image',
        array(
            'title' => 'Landing Page Image',
            'priority' => 35,
        )
    );

    $wp_customize->add_setting(
        'lp-image_selector',
        array(
            'default' => '',
        )
    );

    $wp_customize->add_setting( 'img-upload' );

    $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize,
            'lp-image_selector',
            array(
                'label' => 'Landing Page Image',
                'section' => 'landing_page_image',
                'settings' => 'img-upload'
            )
        )
    );
}
add_action( 'customize_register', 'hi_customization_options' );

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.