Skip to content

Commit

Permalink
Use dynamic URL on front of site
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 4, 2023
1 parent 0e17a60 commit eea7fa8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
$is_post_type = $is_post_type || isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] );

// Don't render the block's subtree if it is a draft or if the ID does not exist.
if ( $is_post_type && $navigation_link_has_id ) {
$post = get_post( $attributes['id'] );
if ( ! $post || 'publish' !== $post->post_status ) {
return '';
}
$post = $is_post_type && $navigation_link_has_id ? get_post( $attributes['id'] ) : null;

if ( ! $post || 'publish' !== $post->post_status ) {
return '';
}


// Don't render the block's subtree if it has no label.
if ( empty( $attributes['label'] ) ) {
return '';
Expand All @@ -159,6 +159,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
$has_submenu = count( $block->inner_blocks ) > 0;
$is_active = ! empty( $attributes['id'] ) && ( get_queried_object_id() === (int) $attributes['id'] );

$theUrl = $post ? get_permalink( $post ) : $attributes['url'];

$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
Expand All @@ -170,8 +172,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
'<a class="wp-block-navigation-item__content" ';

// Start appending HTML attributes to anchor tag.
if ( isset( $attributes['url'] ) ) {
$html .= ' href="' . esc_url( $attributes['url'] ) . '"';
if ( isset( $theUrl ) ) {
$html .= ' href="' . esc_url( $theUrl ) . '"';
}

if ( $is_active ) {
Expand Down

0 comments on commit eea7fa8

Please sign in to comment.