Skip to content

Commit

Permalink
Add a current-menu-ancestor class to navigation items (#40778)
Browse files Browse the repository at this point in the history
* Add a current-menu-ancestor class to menus

* Use WP_HTML_Tag_Processor

* bugfix
  • Loading branch information
aristath authored Dec 1, 2022
1 parent 63991c1 commit 93d317a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
$inner_blocks_html .= $inner_block->render();
}

if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) {
$tag_processor = new WP_HTML_Tag_Processor( $html );
while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item__content' ) ) ) {
$tag_processor->add_class( 'current-menu-ancestor' );
}
$html = $tag_processor->get_updated_html();
}

$html .= sprintf(
'<ul class="wp-block-navigation__submenu-container">%s</ul>',
$inner_blocks_html
Expand Down

0 comments on commit 93d317a

Please sign in to comment.