Skip to content

Commit

Permalink
Fix: Menu Anchor widget renders redundant markup when the anchor ID i…
Browse files Browse the repository at this point in the history
…s empty [ED-13928] (elementor#25334)

Co-authored-by: ElementorBot <[email protected]>
  • Loading branch information
rami-elementor and elementorbot authored Mar 3, 2024
1 parent 3a9374d commit 721c6ff
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions includes/widgets/menu-anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,17 @@ protected function register_controls() {
protected function render() {
$anchor = $this->get_settings_for_display( 'anchor' );

if ( ! empty( $anchor ) ) {
$this->add_render_attribute( 'inner', 'id', sanitize_html_class( $anchor ) );
if ( empty( $anchor ) ) {
return;
}

$this->add_render_attribute( 'inner', 'class', 'elementor-menu-anchor' );
$this->add_render_attribute(
'inner',
[
'class' => 'elementor-menu-anchor',
'id' => sanitize_html_class( $anchor ),
]
);
?>
<div <?php $this->print_render_attribute_string( 'inner' ); ?>></div>
<?php
Expand All @@ -151,7 +157,20 @@ protected function render() {
*/
protected function content_template() {
?>
<div class="elementor-menu-anchor"{{{ settings.anchor ? ' id="' + settings.anchor + '"' : '' }}}></div>
<#
if ( '' === settings.anchor ) {
return;
}

view.addRenderAttribute(
'inner',
{
'class': 'elementor-menu-anchor',
'id': settings.anchor,
}
);
#>
<div {{{ view.getRenderAttributeString( 'inner' ) }}}></div>
<?php
}

Expand Down

0 comments on commit 721c6ff

Please sign in to comment.