Image Dimensions Control

Elementor image dimensions control displays a width input, a height input and an apply button. It is used by the Image Size control to allow the user to set custom width or height for an image.

The control is defined in Control_Image_Dimensions class which extends Control_Base_Multiple class.

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

Arguments

Name Type Default Description
type string image_dimensions 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 false 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.
default array Default image dimension values.

  • $width (int) Image width.
  • $height (int) Image height.

Return Value

(array) An array containing image dimension values:

  • $width (int) Image width.
  • $height (int) Image height.
[
	'width' => '',
	'height' => '',
]

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(
			'custom_dimension',
			[
				'label' => __( 'Image Dimension', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::IMAGE_DIMENSIONS,
				'description' => __( 'Crop the original image size to any custom size. Set custom width or height to keep the original size ratio.', 'plugin-name' ),
				'default' => [
					'width' => '',
					'height' => '',
				],
			]
		);

		$this->end_controls_section();

	}

}