7

I'd like to develop a setting/control for Customizer that allows dynamically to add fields. The typical example would be the possibility to add an unlimited number of slides to an slider in a Theme. There would be a button in the Customizer setting called "Add new slide" that allows to add a new slide field.

For the sake of the responses, let's make it easy: Just a text field per row. So each time we click on a "Add new row" button, a new text field is generated.

I've tried different approaches and my latest one was an attempt to use script templates (Mustache) like this example: http://justintadlock.com/archives/2015/06/05/javascript-templating-in-the-wordpress-customizer

The problem is how to handle dynamically those settings? How to use the WP_Customize_Control to_json function and how to get that Mustache template and duplicate it every time we click on the "Add new" button? I have a very good background on PHP and a medium level on JS so I can understand advanced topics.

2 Answers 2

6

You could use or take a reference from Kirki. It is a framework that allow to add customizer controls with less code.

Take a look to Kirki::Repeater_Control here.

2

This is awesome,have a look it's the best https://github.com/cristian-ungureanu/customizer-repeater

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.