# Icons Control

Icons 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

Name Type Default Description
type string icons 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 false Whether to display the label in a separate line.
separator string default  
default array   The default value is set as an array of value and library
fa4compatibility string   Used to Migrate data from old Icon control, Should be set to the old control name.
recommended array   Used to set the Recommended icons of this Control instance
skin string media Used 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_options array   Used with the inline skin only, to hide an option (Icon Library/SVG) from the inline icon control’s buttons.

# Return Value

[
	'value' => '',
	'library' => '',
]
1
2
3
4

(array) An array containing icon data:

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

# Usage






















 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 








 
 
 





 
 
 
 
 
 





<?php
class Icons_Elementor_Test_Control_Widget extends \Elementor\Widget_Base {

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

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

	protected function register_controls() {

		$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() {
		$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() {
		?>
		<#
		var iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' );
		#>
		<div class="my-icon-wrapper">
			{{{ iconHTML.value }}}
		</div>
		<?php
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70