Skip to content

Commit

Permalink
adds simple dynamic link generation to navigation items
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Mar 20, 2020
1 parent bbc2390 commit f4f54d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function NavigationLinkEdit( {
title: newTitle = '',
url: newURL = '',
opensInNewTab: newOpensInNewTab,
type,
id,
} = {} ) =>
setAttributes( {
Expand Down Expand Up @@ -278,6 +279,7 @@ function NavigationLinkEdit( {
return escape( normalizedURL );
} )(),
opensInNewTab: newOpensInNewTab,
type,
id,
} )
}
Expand Down
14 changes: 13 additions & 1 deletion packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,22 @@ function block_core_navigation_build_html( $attributes, $block, $colors, $font_s
'<a class="wp-block-navigation-link__content"';

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

if (
isset( $block['attrs']['type'] ) &&
isset( $block['attrs']['id'] ) &&
'URL' !== $block['attrs']['type']
) {
$html .= ' href="' . get_permalink( $block['attrs']['id'] ) . '"';
}

if ( isset( $block['attrs']['opensInNewTab'] ) && true === $block['attrs']['opensInNewTab'] ) {
$html .= ' target="_blank" ';
}
Expand Down

0 comments on commit f4f54d5

Please sign in to comment.