I have created a variable number of fields to add images to a nivoslider. It works nicely, but I have to manually refresh the entire page and re-select the section from the customizer panel for the changes to take effect. I'm wondering if there is any way to get the customizer panel itself to refresh by php code, instead of just the live website area.

Here is the code

        'title' => esc_html__('Slider Settings','customslide'),
        'description'   => esc_html__('Add slider images here.','customslide'),
        'priority'      => null

        'default'   => esc_html__('2','customslide'),
        'transport' => 'refresh',
        'sanitize_callback' => 'absint',

        'label' => esc_html__('Number of Slides','customslide'),
        'section'   => 'slider_section',
        'type'  => 'text'

$num_of_slides_value = esc_html(get_theme_mod('num_of_slides','2'));

for ($i=1; $i<$num_of_slides_value+1; $i++) {
    // Slide Image i
        'default'   => get_template_directory_uri().'/images/slides/slider'.$i.'.jpg',
        'sanitize_callback' => 'esc_url_raw',

        new WP_Customize_Image_Control(
                'label' => esc_html__('Slide Image '.$i.' (1440x700)','customslide'),
                'section' => 'slider_section',
                'settings' => 'slide_image'.$i

            'default'   => esc_html__('Responsive Design','customslide'),
            'sanitize_callback' => 'sanitize_text_field',

            'label' => esc_html__('Slide Title '.$i,'customslide'),
            'section'   => 'slider_section',
            'type'  => 'text'

            'default'   => esc_html__('This is description for slider one.','customslide'),
            'sanitize_callback' => 'customslide_format_for_editor',

            'label' => esc_html__('Slide Description '.$i,'customslide'),
            'section' => 'slider_section',
            'setting'   => 'slide_desc'.$i,
            'type'  => 'textarea'

            'default'   => '#link'.$i,
            'sanitize_callback' => 'esc_url_raw',

            'label' => esc_html__('Slide Link '.$i,'customslide'),
            'section'   => 'slider_section',
            'type'      => 'text'


In the current Wordpress version this is not possible, unless you hard write some JS code to dynamically update the customizer panel with your values. I've opened a ticket to update menu locations when switching navigation style, check out it.

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.