0
votes

I'm using Underscores to build a Wordpress 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 like I hoped it would. 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' );

I think I need to add a 'choices' array to the add_control section, but how do I use that to target the media library?

Thanks

1

1 Answers

0
votes

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' );