diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php
index 111598ea4c4860..6747981d640e88 100644
--- a/packages/block-library/src/navigation-link/index.php
+++ b/packages/block-library/src/navigation-link/index.php
@@ -202,6 +202,20 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
return '';
}
+ // Resolve URL binding if present
+ $url = $attributes['url'] ?? '';
+ if ( isset( $attributes['metadata']['bindings']['url']['source'] ) ) {
+ $binding = $attributes['metadata']['bindings']['url'];
+ $source = get_block_bindings_source( $binding['source'] );
+ if ( $source ) {
+ $source_args = $binding['args'] ?? array();
+ $resolved_url = $source->get_value( $source_args, $block, 'url' );
+ if ( $resolved_url ) {
+ $url = $resolved_url;
+ }
+ }
+ }
+
$font_sizes = block_core_navigation_link_build_css_font_sizes( $block->context );
$classes = array_merge(
$font_sizes['css_classes']
@@ -213,9 +227,9 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
$kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
$is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );
- if ( is_post_type_archive() && ! empty( $attributes['url'] ) ) {
+ if ( is_post_type_archive() && ! empty( $url ) ) {
$queried_archive_link = get_post_type_archive_link( get_queried_object()->name );
- if ( $attributes['url'] === $queried_archive_link ) {
+ if ( $url === $queried_archive_link ) {
$is_active = true;
}
}
@@ -231,8 +245,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
'get_value( $source_args, $block, 'url' );
+ if ( $resolved_url ) {
+ $url = $resolved_url;
+ }
+ }
+ }
+
$font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context );
$style_attribute = $font_sizes['inline_styles'];
@@ -86,9 +100,9 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
$kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
$is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );
- if ( is_post_type_archive() && ! empty( $attributes['url'] ) ) {
+ if ( is_post_type_archive() && ! empty( $url ) ) {
$queried_archive_link = get_post_type_archive_link( get_queried_object()->name );
- if ( $attributes['url'] === $queried_archive_link ) {
+ if ( $url === $queried_archive_link ) {
$is_active = true;
}
}
@@ -142,7 +156,7 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
// If Submenus open on hover, we render an anchor tag with attributes.
// If submenu icons are set to show, we also render a submenu button, so the submenu can be opened on click.
if ( ! $open_on_click ) {
- $item_url = isset( $attributes['url'] ) ? $attributes['url'] : '';
+ $item_url = $url;
// Start appending HTML attributes to anchor tag.
$html .= '