Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submenu block href only if url is not empty #44337

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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