-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Home link: Allow usage outside the navigation block #60558
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
// If the home link is inside a navigation block, it should be wrapped in a list item with additional attributes. | ||
// Use the block context to determine if the home link is inside a navigation block. | ||
$in_navigation = ! empty( $block->context ); | ||
|
||
if ( $in_navigation ) { | ||
$item_markup = '<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%3$s" rel="home"%4$s>%5$s</a></li>'; | ||
} else { | ||
$item_markup = '<a %2$s href="%3$s" rel="home"%4$s>%5$s</a>'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be better covered via the block_core_navigation_listable_blocks
filter introduced in 6.5.
Or you can add the block to the default array here:
gutenberg/packages/block-library/src/navigation/index.php
Lines 23 to 26 in e4623e1
private static $needs_list_item_wrapper = array( | |
'core/site-title', | |
'core/site-logo', | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Thanks I will look those up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though how would I avoid it breaking on 6.3, 6.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mostly thinking out loud, but this block would also need the current-menu-item class on the li.
The challenge here is to not break backwards compatibility. Here is an example of a home link inside the navigation block without this PR:
Note the duplicate font sizes. The small font size is set on the navigation block, and the large is set on the home link. If I switch to using the
So existing third-party CSS used to style the home link will break. |
I created a separate branch with the changes that I mentioned above, where the list item is removed from home-link index.php and the block is added to $ |
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ packages/block-library/src/home-link/index.php |
Flaky tests detected in 8d97521. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9204828530
|
What?
Allows the home link block outside the navigation block.
Partial for #49282
Closes #35926
Why?
It is a more convenient way for end-users to add links to the home page without needing to use a navigation block, site logo, or block bindings API.
How?
The PR:
showSubmenuIcon
tousesContext
in block.json, because compared to for example colors, this attribute it always set on the navigation block, so, it can be used to determine if the Home link block is inside the navigation block or not.<a>
or<li>
depending on where it is placed.Testing Instructions
Test this in both a template or template part and in a post or page.
Add a navigation block with a home link block inside.
Add a standalone home link block.
Confirm that both copies of the block work correctly in the editors and front:
aria-current="page"
is still present on the block when it is placed on the home page.Testing Instructions for Keyboard
Feedback needed:
What is the correct element to use when the block is not inside the navigation block?
Screenshots or screencast