if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
* Elementor widget that displays an icon from over 600+ icons.
class Widget_Icon extends Widget_Base {
* Retrieve icon widget name.
* @return string Widget name.
public function get_name() {
* Retrieve icon widget title.
* @return string Widget title.
public function get_title() {
return esc_html__( 'Icon', 'elementor' );
* Retrieve icon widget icon.
* @return string Widget icon.
public function get_icon() {
* Retrieve the list of categories the icon widget belongs to.
* Used to determine where to display the widget in the editor.
* @return array Widget categories.
public function get_categories() {
public function has_widget_inner_wrapper(): bool {
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
* Retrieve the list of keywords the widget belongs to.
* @return array Widget keywords.
public function get_keywords() {
protected function is_dynamic_content(): bool {
* Register icon widget controls.
* Adds different input fields to allow the user to change and customize the widget settings.
protected function register_controls() {
$this->start_controls_section(
'label' => esc_html__( 'Icon', 'elementor' ),
'label' => esc_html__( 'Icon', 'elementor' ),
'type' => Controls_Manager::ICONS,
'fa4compatibility' => 'icon',
'value' => 'fas fa-star',
'label' => esc_html__( 'View', 'elementor' ),
'type' => Controls_Manager::SELECT,
'default' => esc_html__( 'Default', 'elementor' ),
'stacked' => esc_html__( 'Stacked', 'elementor' ),
'framed' => esc_html__( 'Framed', 'elementor' ),
'prefix_class' => 'elementor-view-',
'label' => esc_html__( 'Shape', 'elementor' ),
'type' => Controls_Manager::SELECT,
'square' => esc_html__( 'Square', 'elementor' ),
'rounded' => esc_html__( 'Rounded', 'elementor' ),
'circle' => esc_html__( 'Circle', 'elementor' ),
'prefix_class' => 'elementor-shape-',
'label' => esc_html__( 'Link', 'elementor' ),
'type' => Controls_Manager::URL,
$this->end_controls_section();
$this->start_controls_section(
'label' => esc_html__( 'Icon', 'elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
$this->add_responsive_control(
'label' => esc_html__( 'Alignment', 'elementor' ),
'type' => Controls_Manager::CHOOSE,
'title' => esc_html__( 'Start', 'elementor' ),
'icon' => 'eicon-text-align-left',
'title' => esc_html__( 'Center', 'elementor' ),
'icon' => 'eicon-text-align-center',
'title' => esc_html__( 'End', 'elementor' ),
'icon' => 'eicon-text-align-right',
'classes' => 'elementor-control-start-end',
'selectors_dictionary' => [
'left' => is_rtl() ? 'end' : 'start',
'right' => is_rtl() ? 'start' : 'end',
'{{WRAPPER}} .elementor-icon-wrapper' => 'text-align: {{VALUE}};',
$this->start_controls_tabs( 'icon_colors' );
$this->start_controls_tab(
'label' => esc_html__( 'Normal', 'elementor' ),
'label' => esc_html__( 'Primary Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon svg' => 'fill: {{VALUE}};',
'default' => Global_Colors::COLOR_PRIMARY,
'label' => esc_html__( 'Secondary Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon svg' => 'fill: {{VALUE}};',
$this->end_controls_tab();
$this->start_controls_tab(
'label' => esc_html__( 'Hover', 'elementor' ),
'label' => esc_html__( 'Primary Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover svg' => 'fill: {{VALUE}};',
'label' => esc_html__( 'Secondary Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover svg' => 'fill: {{VALUE}};',
'label' => esc_html__( 'Hover Animation', 'elementor' ),
'type' => Controls_Manager::HOVER_ANIMATION,
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_responsive_control(
'label' => esc_html__( 'Size', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
'{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
'{{WRAPPER}} .elementor-icon svg' => 'height: {{SIZE}}{{UNIT}};',
'label' => esc_html__( 'Fit to Size', 'elementor' ),
'type' => Controls_Manager::SWITCHER,
'description' => 'Avoid gaps around icons when width and height aren\'t equal',
'label_off' => esc_html__( 'Off', 'elementor' ),
'label_on' => esc_html__( 'On', 'elementor' ),
'selected_icon[library]' => 'svg',
'{{WRAPPER}} .elementor-icon-wrapper svg' => 'width: auto;',
'label' => esc_html__( 'Padding', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
$this->add_responsive_control(
'label' => esc_html__( 'Rotate', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'deg', 'grad', 'rad', 'turn', 'custom' ],
'{{WRAPPER}} .elementor-icon i, {{WRAPPER}} .elementor-icon svg' => 'transform: rotate({{SIZE}}{{UNIT}});',
'label' => esc_html__( 'Border Width', 'elementor' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
'{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
$this->add_responsive_control(
'label' => esc_html__( 'Border Radius', 'elementor' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
'{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
$this->end_controls_section();
* Render icon widget output on the frontend.
* Written in PHP and used to generate the final HTML.
protected function render() {
$settings = $this->get_settings_for_display();
if ( empty( $settings['selected_icon']['value'] ) ) {
$this->add_render_attribute( 'wrapper', 'class', 'elementor-icon-wrapper' );
$this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-icon' );
if ( ! empty( $settings['hover_animation'] ) ) {
$this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-animation-' . $settings['hover_animation'] );
if ( ! empty( $settings['link']['url'] ) ) {
$this->add_link_attributes( 'icon-wrapper', $settings['link'] );
if ( empty( $settings['icon'] ) && ! Icons_Manager::is_migration_allowed() ) {
$settings['icon'] = 'fa fa-star';
if ( ! empty( $settings['icon'] ) ) {
$this->add_render_attribute( 'icon', 'class', $settings['icon'] );
$this->add_render_attribute( 'icon', 'aria-hidden', 'true' );
$migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
$is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
<div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
<<?php Utils::print_validated_html_tag( $icon_tag ); ?> <?php $this->print_render_attribute_string( 'icon-wrapper' ); ?>>
<?php if ( $is_new || $migrated ) :
Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
<i <?php $this->print_render_attribute_string( 'icon' ); ?>></i>
</<?php Utils::print_validated_html_tag( $icon_tag ); ?>>
* Render icon widget output in the editor.
* Written as a Backbone JavaScript template and used to generate the live preview.
protected function content_template() {
if ( '' === settings.selected_icon.value ) {