option_type

When registering controls in Kirki, they are saved as theme_mods by default.

If you choose to save your settings as options, you can do so by passing the option_type argument to all controls like so:

'option_type' => 'option',

When switching the option_type from theme_mods to option, it is important that you also pass an option_name to keep things organized. If no specific option_name is given, the settings value will be used as the option name.

In the example below, the first 2 color fields will save their values in a single option (all_my_options). The third control will save a separate option in the database named my_standalone_option while the 4th example doesn’t specify an option name and therefore will use kirki_demo_color_hex_3 as the option name.

/**
* Value will be saved under 'all_my_options' in the database.
*/
new \Kirki\Field\Color(
	[
		'option_type' => 'option',
		'option_name' => 'all_my_options',
		'settings'    => 'kirki_demo_color_hex_1',
		'label'       => __( 'Hex Color 1', 'kirki' ),
		'section'     => 'color_section',
		'default'     => '#0008DC',
	]
);

/**
* Value will be saved under 'all_my_options' in the database.
*/
new \Kirki\Field\Color(
	[
		'option_type' => 'option',
		'option_name' => 'all_my_options',
		'settings'    => 'kirki_demo_color_hex_2',
		'label'       => __( 'Hex Color 2', 'kirki' ),
		'section'     => 'color_section',
		'default'     => '#0008DC',
	]
);

/**
* Value will be saved under 'my_standalone_option' in the database.
*/
new \Kirki\Field\Color(
	[
		'option_type' => 'option',
		'option_name' => 'my_standalone_option',
		'settings'    => 'kirki_demo_color_hex_3',
		'label'       => __( 'Hex Color 3', 'kirki' ),
		'section'     => 'color_section',
		'default'     => '#0008DC',
	]
);

/**
* Value will be saved under 'kirki_demo_color_hex_3' in the database as no option_name is provided.
*/
new \Kirki\Field\Color(
	[
		'option_type' => 'option',
		'settings'    => 'kirki_demo_color_hex_3',
		'label'       => __( 'Hex Color 3', 'kirki' ),
		'section'     => 'color_section',
		'default'     => '#0008DC',
	]
);

Was this helpful?