color

The color control allows you to create colorpickers. WordPress uses iris for colorpickers and Kirki extends the default WordPress Color controls adding the ability to select rgba colors with the addition of an opacity slider.

Example

Adding a hex-only colorpicker

Kirki::add_field( 'theme_config_id', [
	'type'        => 'color',
	'settings'    => 'color_setting_hex',
	'label'       => __( 'Color Control (hex-only)', 'kirki' ),
	'description' => esc_html__( 'This is a color control - without alpha channel.', 'kirki' ),
	'section'     => 'section_id',
	'default'     => '#0088CC',
] );

Adding an rgba colorpicker

Kirki::add_field( 'theme_config_id', [
	'type'        => 'color',
	'settings'    => 'color_setting_rgba',
	'label'       => __( 'Color Control (with alpha channel)', 'kirki' ),
	'description' => esc_html__( 'This is a color control - with alpha channel.', 'kirki' ),
	'section'     => 'section_id',
	'default'     => '#0088CC',
	'choices'     => [
		'alpha' => true,
	],
] );

Adding a hue-only colorpicker

Kirki::add_field( 'theme_config_id', [
	'type'        => 'color',
	'settings'    => 'color_setting_hue',
	'label'       => __( 'Color Control - hue only.', 'kirki' ),
	'description' => esc_html__( 'This is a color control - hue only.', 'kirki' ),
	'section'     => 'section_id',
	'default'     => '#0088CC',
	'mode'        => 'hue',
] );

Caution:

If you use a hue-only control the saved value will not be a hex or rgba color. Instead the value will be an integer. You can use that value in HSL or HSLA colors in your themes. For more info on HSLA you can read this article

Usage

Most times you won’t have to manually retrieve the value of color controls since the output argument can cover most use-cases.

<div style="color:<?php echo get_theme_mod( 'color_setting_hex', '#FFFFFF' ); ?>">
	<p>The text-color of this div is controlled by "color_setting_hex".
</div>

Last updated on: May 10th, 2020

Scroll to Top

Download

Subscribe & be the first to be informed about
new features & updates!