Skip to content

Commit

Permalink
Nav Submenu - omit href attribute on front of site if url is empty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave authored and ockham committed Sep 26, 2022
1 parent 896fc77 commit 5fda1e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
if ( ! $open_on_click ) {
$item_url = isset( $attributes['url'] ) ? $attributes['url'] : '';
// Start appending HTML attributes to anchor tag.
$html .= '<a class="wp-block-navigation-item__content" href="' . esc_url( $item_url ) . '"';
$html .= '<a class="wp-block-navigation-item__content"';

// The href attribute on a and area elements is not required;
// when those elements do not have href attributes they do not create hyperlinks.
// But also The href attribute must have a value that is a valid URL potentially
// surrounded by spaces.
// see: https://html.spec.whatwg.org/multipage/links.html#links-created-by-a-and-area-elements.
if ( ! empty( $item_url ) ) {
$html .= ' href="' . esc_url( $item_url ) . '"';
}

if ( $is_active ) {
$html .= ' aria-current="page"';
Expand Down

0 comments on commit 5fda1e6

Please sign in to comment.