Input Slider

Theย Input Sliderย is a hybrid control. It is a combination of theย Text Fieldย &ย Sliderย control.

Input Slider

Whatโ€™s special about the Input Slider is, that it allows for all possible units. Meaning, the user can easily enter what ever value they desire. No matter if thatโ€™s 50px, 5rem, or 50%.

Similar to the Slider control, you can pass the minmax & step value in the choices argument.

new \Kirki\Pro\Field\InputSlider(
	[
		'settings'    => 'kirki_pro_slider',
		'label'       => esc_html__( 'Responsive Slider Control', 'kirki' ),
		'section'     => 'section_id',
		'transport'   => 'postMessage',
		'default'     => '50px',
		'choices'     => [
			'min'  => 0,
			'max'  => 100,
			'step' => 1,
		],
	]
);

Usage

The Input Slider does work with theย outputย argument, just like any other control. For more flexibility & manually retrieving the value, please have a look at the example below.

Getting the value of the input slider is simple.

In the example below, we useย pxย it as the fallback if no unit is defined by the user in the field. We also prevent the output if theย defaultย value has been saved.

$value = ( $val = get_theme_mod( 'kirki_pro_slider' ) ) === '50px' ? false : $val;

if ( $value ) {
	$suffix = is_numeric( $value ) ? 'px' : '';
	echo '.my-element {';
	echo sprintf( 'width: %s;', esc_attr( $value ) . $suffix );
	echo '}';
}

How can we help?

Was this helpful?