if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Modules\ContentSanitizer\Interfaces\Sanitizable;
use Elementor\Core\Utils\Hints;
use Elementor\Core\Admin\Admin_Notices;
use Elementor\Modules\Promotions\Controls\Promotion_Control;
* Elementor heading widget.
* Elementor widget that displays an eye-catching headlines.
class Widget_Heading extends Widget_Base implements Sanitizable {
* Retrieve heading widget name.
* @return string Widget name.
public function get_name() {
* Retrieve heading widget title.
* @return string Widget title.
public function get_title() {
return esc_html__( 'Heading', 'elementor' );
* Retrieve heading widget icon.
* @return string Widget icon.
public function get_icon() {
* Retrieve the list of categories the heading widget belongs to.
* Used to determine where to display the widget in the editor.
* @return array Widget categories.
public function get_categories() {
* Retrieve the list of keywords the widget belongs to.
* @return array Widget keywords.
public function get_keywords() {
return [ 'heading', 'title', 'text' ];
protected function is_dynamic_content(): bool {
* Get style dependencies.
* Retrieve the list of style dependencies the widget requires.
* @return array Widget style dependencies.
public function get_style_depends(): array {
return [ 'widget-heading' ];
public function has_widget_inner_wrapper(): bool {
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
* Remove data attributes from the html.
* @param string $content Heading title.
public function sanitize( $content ): string {
$allowed_tags = wp_kses_allowed_html( 'post' );
$allowed_tags_for_heading = [];
$non_allowed_tags = [ 'img' ];
foreach ( $allowed_tags as $tag => $attributes ) {
if ( in_array( $tag, $non_allowed_tags, true ) ) {
$filtered_attributes = array_filter( $attributes, function( $attribute ) {
return ! substr( $attribute, 0, 5 ) === 'data-';
}, ARRAY_FILTER_USE_KEY );
$allowed_tags_for_heading[ $tag ] = $filtered_attributes;
return wp_kses( $content, $allowed_tags_for_heading );
* Get widget upsale data.
* Retrieve the widget promotion data.
* @return array Widget promotion data.
protected function get_upsale_data() {
'condition' => ! Utils::has_pro(),
'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
'image_alt' => esc_attr__( 'Upgrade', 'elementor' ),
'description' => esc_html__( 'Create captivating headings that rotate with the Animated Headline Widget.', 'elementor' ),
'upgrade_url' => esc_url( 'https://go.elementor.com/go-pro-heading-widget/' ),
'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ),
* Register heading 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__( 'Heading', 'elementor' ),
'label' => esc_html__( 'Title', 'elementor' ),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
'default' => esc_html__( 'Add Your Heading Text Here', 'elementor' ),
'label' => esc_html__( 'Link', 'elementor' ),
'type' => Controls_Manager::URL,
'label' => esc_html__( 'Size', 'elementor' ),
'type' => Controls_Manager::SELECT,
'default' => esc_html__( 'Default', 'elementor' ),
'small' => esc_html__( 'Small', 'elementor' ),
'medium' => esc_html__( 'Medium', 'elementor' ),
'large' => esc_html__( 'Large', 'elementor' ),
'xl' => esc_html__( 'XL', 'elementor' ),
'xxl' => esc_html__( 'XXL', 'elementor' ),
'size!' => 'default', // a workaround to hide the control, unless it's in use (not default).
'label' => esc_html__( 'HTML Tag', 'elementor' ),
'type' => Controls_Manager::SELECT,
$this->maybe_add_ally_heading_hint();
$this->end_controls_section();
$this->start_controls_section(
'label' => esc_html__( 'Heading', 'elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
$this->add_responsive_control(
'label' => esc_html__( 'Alignment', 'elementor' ),
'type' => Controls_Manager::CHOOSE,
'title' => esc_html__( 'Left', 'elementor' ),
'icon' => 'eicon-text-align-left',
'title' => esc_html__( 'Center', 'elementor' ),
'icon' => 'eicon-text-align-center',
'title' => esc_html__( 'Right', 'elementor' ),
'icon' => 'eicon-text-align-right',
'title' => esc_html__( 'Justified', 'elementor' ),
'icon' => 'eicon-text-align-justify',
'{{WRAPPER}}' => 'text-align: {{VALUE}};',
$this->add_group_control(
Group_Control_Typography::get_type(),
'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
'selector' => '{{WRAPPER}} .elementor-heading-title',
$this->add_group_control(
Group_Control_Text_Stroke::get_type(),
'selector' => '{{WRAPPER}} .elementor-heading-title',
$this->add_group_control(
Group_Control_Text_Shadow::get_type(),
'selector' => '{{WRAPPER}} .elementor-heading-title',
'label' => esc_html__( 'Blend Mode', 'elementor' ),
'type' => Controls_Manager::SELECT,
'' => esc_html__( 'Normal', 'elementor' ),
'multiply' => esc_html__( 'Multiply', 'elementor' ),
'screen' => esc_html__( 'Screen', 'elementor' ),
'overlay' => esc_html__( 'Overlay', 'elementor' ),
'darken' => esc_html__( 'Darken', 'elementor' ),
'lighten' => esc_html__( 'Lighten', 'elementor' ),
'color-dodge' => esc_html__( 'Color Dodge', 'elementor' ),
'saturation' => esc_html__( 'Saturation', 'elementor' ),
'color' => esc_html__( 'Color', 'elementor' ),
'difference' => esc_html__( 'Difference', 'elementor' ),
'exclusion' => esc_html__( 'Exclusion', 'elementor' ),
'hue' => esc_html__( 'Hue', 'elementor' ),
'luminosity' => esc_html__( 'Luminosity', 'elementor' ),
'{{WRAPPER}} .elementor-heading-title' => 'mix-blend-mode: {{VALUE}}',
'type' => Controls_Manager::DIVIDER,
$this->start_controls_tabs( 'title_colors' );
$this->start_controls_tab(
'label' => esc_html__( 'Normal', 'elementor' ),
'label' => esc_html__( 'Text Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'default' => Global_Colors::COLOR_PRIMARY,
'{{WRAPPER}} .elementor-heading-title' => 'color: {{VALUE}};',
$this->end_controls_tab();
$this->start_controls_tab(
'label' => esc_html__( 'Hover', 'elementor' ),
'label' => esc_html__( 'Link Color', 'elementor' ),
'type' => Controls_Manager::COLOR,
'{{WRAPPER}} .elementor-heading-title a:hover, {{WRAPPER}} .elementor-heading-title a:focus' => 'color: {{VALUE}};',
'title_hover_color_transition_duration',
'label' => esc_html__( 'Transition Duration', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 's', 'ms', 'custom' ],
'{{WRAPPER}} .elementor-heading-title a' => 'transition-duration: {{SIZE}}{{UNIT}};',
$this->end_controls_tab();
$this->end_controls_tabs();
$this->end_controls_section();
* Render heading 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 ( '' === $settings['title'] ) {
$this->add_render_attribute( 'title', 'class', 'elementor-heading-title' );
if ( ! empty( $settings['size'] ) ) {
$this->add_render_attribute( 'title', 'class', 'elementor-size-' . $settings['size'] );
$this->add_render_attribute( 'title', 'class', 'elementor-size-default' );
$this->add_inline_editing_attributes( 'title' );
$title = wp_kses_post( $settings['title'] );
if ( ! empty( $settings['link']['url'] ) ) {
$this->add_link_attributes( 'url', $settings['link'] );
$title = sprintf( '<a %1$s>%2$s</a>', $this->get_render_attribute_string( 'url' ), $title );
$title_html = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $settings['header_size'] ), $this->get_render_attribute_string( 'title' ), $title );
// PHPCS - the variable $title_html holds safe data.
echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
public function maybe_add_ally_heading_hint() {
$notice_id = 'ally_heading_notice';
$plugin_slug = 'pojo-accessibility';
if ( ! Hints::should_display_hint( $notice_id ) ) {
$notice_content = esc_html__( 'Make sure your page is structured with accessibility in mind. Ally helps detect and fix common issues across your site.', 'elementor' );
'name' => 'elementor_ea11y_campaign',
'campaign' => 'acc-scanner-plg-heading',
'source' => 'editor-heading-widget',
$button_text = __( 'Install Plugin', 'elementor' );
$action_url = Admin_Notices::add_plg_campaign_data( Hints::get_plugin_action_url( $plugin_slug ), $campaign_data );
if ( Hints::is_plugin_installed( $plugin_slug ) && ! Hints::is_plugin_active( $plugin_slug ) ) {
$button_text = __( 'Activate Plugin', 'elementor' );
} else if ( Hints::is_plugin_active( $plugin_slug ) && empty( get_option( 'ea11y_access_token' ) ) ) {
$button_text = __( 'Connect to Ally', 'elementor' );
$action_url = admin_url( 'admin.php?page=accessibility-settings' );
'type' => Controls_Manager::RAW_HTML,
'raw' => Hints::get_notice_template( [
'display' => ! Hints::is_dismissed( $notice_id ),
'heading' => esc_html__( 'Accessible structure matters', 'elementor' ),
'content' => $notice_content,
'dismissible' => $notice_id,
'button_text' => $button_text,
'button_event' => $notice_id,
'action_url' => $action_url,