I ended up integrating Kirki in my theme.
How to integrate it:
I created a new folder, named includes
in my theme. Then, in my functions.php, i added this line:
include_once( dirname( __FILE__ ) . '/include/kirki/kirki.php' );
Now, the main point: create replicable items
Kirki features a bigger list of control types. The one we want is named repeater
. To use it (as with any of Kirki’s controls) you need to create a config
and a section
, but the setting is auto-created:
Kirki::add_config('awesome_config', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
));
Kirki::add_section('awesome_section', array(
'title' => _('Awesome section'),
'description' => _(''),
'capability' => 'edit_theme_options'
));
Now, keeping in mind these 2 elements, we can finally create our repeater control:
Kirki::add_field('awesome_config', array (
'type' => 'repeater',
'settings' => 'awesome_setting',
'label' => _('Awesome repeater'),
'section' => 'awesome_section',
'fields' => array(
'field1' => array(
'type' => 'text',
'label' => _('Field 1'),
'default' => ''
),
'field2' => array(
'type' => 'text',
'label' => _('Field 2'),
'default' => ''
),
)
));
As shown, you can not only create fields that user can replicate, but also add many fields in there!