Slider Control

Elementor slider control displays a draggable range slider. The slider control can optionally have a number of unit types (size_units) for the user to choose from. The control also accepts a range argument that allows you to set the min, max and step values per unit type.

The control is defined in Control_Slider class which extends Control_Base_Units class.

Note that when using the control, the type should be set using the \Elementor\Controls_Manager::SLIDER constant.

Arguments

Name Type Default Description
type string slider The type of the control.
label string The label that appears above of the field.
description string The description that appears below the field.
show_label bool true Whether to display the label.
label_block bool true Whether to display the label in a separate line.
separator string default Set the position of the control separator. Available values are default, before, after and none. default will position the separator depending on the control type. before / after will position the separator before/after the control. none will hide the separator.
size_units array [ ‘px’ ] An array of available CSS units like px, em, rem, %, deg and vh.
range array An array of ranges for each register size.

  • $min (int) The minimum value of range.
  • $max (int) The maximum value of range.
  • $step (int) The intervals value that will be incremented or decremented when using the controls’ spinners.
default array Default slider value.

  • $unit (string) Initial unit of the slider.
  • $size (int) Initial size of the slider.

Return Value

(array) An array containing the dimension values:

  • $unit (string) Selected unit.
  • $size (int) Selected size.
[
	'unit' => '',
	'size' => '',
]

Usage

<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {

	protected function _register_controls() {

		$this->start_controls_section(
			'content_section',
			[
				'label' => __( 'Content', 'plugin-name' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'width',
			[
				'label' => __( 'Width', 'plugin-domain' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => '%',
					'size' => 50,
				],
				'selectors' => [
					'{{WRAPPER}} .box' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_section();

	}

	protected function render() {
		$settings = $this->get_settings_for_display();
		echo '<div class="box" style="width: ' . $settings['width']['size'] . $settings['width']['unit'] '"> ... </div>';
	}

	protected function _content_template() {
		?>
		<div class="box" style="width: {{ settings.width.size }}{{ settings.width.unit }}"> ... </div>';
		<?php
	}

}