//--- Heading Widget
// Extend Elementor's heading widget to add a CSS class based on the alignment setting so we can also control the position of the underline
- add_action( 'elementor/element/heading/section_title/before_section_end', function( $element, $args ) {
- $elementor = Plugin::instance();
-
- // Get the align control for updating
- $control_data = $elementor->controls_manager->get_control_from_stack( $element->get_name(), 'align' );
-
- if (is_wp_error($control_data)) {
- return;
+ add_action( 'elementor/widget/before_render_content', function( $widget ) {
+ if ('heading' === $widget->get_name()) {
+ $settings = $widget->get_settings();
+ if ( ! empty( $settings['align'] ) ) {
+ $widget->add_render_attribute('_wrapper', 'class', 'heading-align-'. $settings['align']);
+ }
}
-
- // Add a prefix class so heading will have correct class applied when alignment is changed
- $control_data['prefix_class'] = 'heading-align-';
- $element->update_control( 'align', $control_data );
- }, 10, 2);
+ });
// Todo: consider add a control to the existing heading widget that allows the underline to be disabled (via prefix_class?)
$element->update_control( 'icon_active', $icon_active_control );
}, 10, 2);
-
}
public function register_widgets() {
}
-}
+}
\ No newline at end of file