Xarcell
Xarcell

Reputation: 2011

How Do you Properly Add An Image Control To Wordpress Customizer?

Wordpress admin customizer control is incomplete. How can I fix it?

My Code:

$wp_customize->add_setting('swag_header_media');
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
    'label'            => 'Current Image Selection',
    'section'          => 'swag_header_media_section',
    'active_callback'  => 'header_show_image_selection_settings_callback',
    'settings'         => 'swag_header_media'
)));

The results are incomplete. I can select an image from the and the image show up in the frontend of the theme. However, the image selected does not show that it is being used in the control.

In other words(see screenshot), you can see the background image being used(phone), but it doesn't show that it being used in the admin customizer control. Its says "Current Image Selection", but it's empty with no buttons below it to change or remove it.

enter image description here

Upvotes: 3

Views: 1032

Answers (2)

T.Todua
T.Todua

Reputation: 56351

Try:

$wp_customize->add_setting('themename_theme_mods[swag_header_media]',array(
    //'default'           => 'image.jpg',
    //'capability'        => 'edit_theme_options',
    //'type'              => 'option'
));

$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
    'label'            => 'Current Image Selection',
    'section'          => 'swag_header_media_section',
    'active_callback'  => 'header_show_image_selection_settings_callback',
    'settings'         => 'themename_theme_mods[swag_header_media]'
)));

if that doesnt work,I suggest to change swag_header_media to other keyname. I suspect that key name might be used by other control/funtion too. So, try to add any 1 letter to that keyname, and see the result. Also, if you have any caching on site, turn it off.

also, the problem could be with callback,

Upvotes: 0

Shado
Shado

Reputation: 135

When you inspect the page, is there any errors?

It is a bit hard to figure out with so little data.

Try this 'settings' => 'themename_theme_options[swag_header_media]',

Upvotes: 1

Related Questions