Skip to content

Icons Control

Elementor Core BasicIcons Control

Elementor Icons control displays the icons chooser. In addition, it has the abilitiy to select existing icons from Elementor's "Icon Library" or "Upload SVG" to WordPress media library.

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

When using this control, the type should be set to \Elementor\Controls_Manager::ICONS constant.

Arguments

NameTypeDefaultDescription
typestringiconsThe type of the control.
labelstring The label that appears above of the field.
descriptionstring The description that appears below the field.
show_labelbooltrueWhether to display the label.
label_blockboolfalseWhether to display the label in a separate line.
separatorstringdefault 
defaultarray The default value is set as an array of value and library
fa4compatibilitystring Used to Migrate data from old Icon control, Should be set to the old control name.
recommendedarray Used to set the Recommended icons of this Control instance
skinstringmediaUsed to change the appearance of the control. There are two options: media or inline. The inline skin’s design is based on the Choose Control.
exclude_inline_optionsarray Used with the inline skin only, to hide an option (Icon Library/SVG) from the inline icon control’s buttons.

Return Value

[
	'value' => '',
	'library' => '',
]

(array) An array containing icon data:

  • $value (string) Icon value.
  • $library (string) Icon library name.

Usage

php
<?php
class Icons_Elementor_Test_Control_Widget extends \Elementor\Widget_Base {

	public function get_name(): string {
		return 'icons_test_widget';
	}

	public function get_title(): string {
		return esc_html__( 'Icons Test Widget', 'textdomain' );
	}

	protected function register_controls(): void {

		$this->start_controls_section(
			'section_icon',
			[
				'label' => esc_html__( 'Icon', 'textdomain' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'icon',
			[
				'label' => esc_html__( 'Icon', 'textdomain' ),
				'type' => \Elementor\Controls_Manager::ICONS,
				'default' => [
					'value' => 'fas fa-circle',
					'library' => 'fa-solid',
				],
				'recommended' => [
					'fa-solid' => [
						'circle',
						'dot-circle',
						'square-full',
					],
					'fa-regular' => [
						'circle',
						'dot-circle',
						'square-full',
					],
				],
			]
		);

		$this->end_controls_section();

	}

	protected function render(): void {
		$settings = $this->get_settings_for_display();
		?>
		<div class="my-icon-wrapper">
			<?php \Elementor\Icons_Manager::render_icon( $settings['icon'], [ 'aria-hidden' => 'true' ] ); ?>
		</div>
		<?php
	}

	protected function content_template(): void {
		?>
		<#
		const iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' );
		#>
		<div class="my-icon-wrapper">
			{{{ iconHTML.value }}}
		</div>
		<?php
	}

}