The "multicheck" control

Learn how to create controls using Kirki

Back to Controls

Returnsarray

The documentation site is currently being rewritten. If you can't find what you're looking for please check the github issues and ask for assistance there until the documentation rewrite is complete.

On Multicheck fields, you can specify the options that will be available to your users by editing the choices argument and specifying an array of options in the form of key => label.

Please keep in mind that you should always use WordPress’s i18n functions for your labels and descriptions so they are translatable. More information on WordPress’s i18n functions can be found on the WordPress Codex.

Example

Kirki::add_field( 'theme_config_id', array(
	'type'        => 'multicheck',
	'settings'    => 'my_setting',
	'label'       => esc_attr__( 'My Control', 'textdomain' ),
	'section'     => 'section_id',
	'default'     => array('option-1', 'option-3', 'option-4'),
	'priority'    => 10,
	'choices'     => array(
		'option-1' => esc_attr__( 'Option 1', 'textdomain' ),
		'option-2' => esc_attr__( 'Option 2', 'textdomain' ),
		'option-3' => esc_attr__( 'Option 3', 'textdomain' ),
		'option-4' => esc_attr__( 'Option 4', 'textdomain' ),
		'option-5' => esc_attr__( 'Option 5', 'textdomain' ),
	),
) );

Usage

<?php $multicheck_value = get_theme_mod( 'my_setting', array( 'option-1', 'option-3' ) ); ?>
<?php if ( ! empty( $multicheck_value ) ) : ?>
  <ul>
	<?php foreach ( $multicheck_value as $checked_value ) : ?>
		<li><?php echo $checked_value; ?></li>
	<?php endforeach; ?>
  </ul>
<?php endif; ?>

Please keep in mind that the returned values are the keys of the settings you have defined, not their labels. If you want to display the labels then you will have to implement this on your code.

Edit this page