I am trying to make the Customizer panel for a Slider in WordPress. I have Sections in a Panel. In the first section, I have a checkbox and a number field.

I want to show the number of sections based on the number in the number field and it needs to change dynamically. For Example, If I have 3 in the number field, then only 3 Slider sections are visible.

Also, all the sections and the number field are toggled by the checkbox.

I have been looking into the JS API for customizer and the most I have been able to achieve is toggling the number field. The Sections don't seem to move anywhere. activate() and deactivate() but to no avail. The js file I have been writing the script in has been hooked to customize_controls_enqueue_scripts -

function mytheme_customize_control_js() {
    wp_enqueue_script( 'mytheme_customizer_control', get_template_directory_uri() . '/assets/js/customizer-control.js', array( 'customize-preview' ), '20130509', true );

add_action('customize_controls_enqueue_scripts', 'mytheme_customize_control_js');

JS API is preferred but the one with active_callback will also work since that too did not work for me.

  • it's not impossible to have dynamic sections but it would be a big amount of work to code that in JavaScript. a easier way could be to use a widget for each slider. and then you create a sidebar that can store any amount of sliders. – mmm May 20 '18 at 10:42
  • @mmm got it! Will try that for sure. Meanwhile, can you tell me that if such an arrangement will be possible using active_callback. – Divjot Singh May 22 '18 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.