-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add Post Type Archive variation to core/navigation-link
block
#31452
Comments
Yup, thanks for double checking, @gwwar ! |
+1 This issue is... not fun to work around. Thanks! |
This issue is the one reason I still have to remove archives and use normal pages instead,(1) the navigation-block doesn't recognize them. (2) the 'is-active' class is not placed on it, making standard navigation UX totally impossible. Not fun indeed. Such a standard and crucial feature that still doesn't work after 1 year of FSE. |
+1 This should be considered a core aspect of the nav block, we have categories and custom taxonomies, we dont have a user friendly way of adding an archive page.
IMO, it should be high priority seeing as this should be one of the fundamentals of the nav |
@scruffian @priethor Should we look to pull this into the scope of work for 6.3? Seems achievable. |
@getdave I think the Nav block experience is in a stage where we can re-prioritize this kind of issues; it seems a good thing to tackle for 6.3 |
Added to |
As a stop-gap, I wrote this quick and dirty JS function to add Maybe there is a better way to do it server-side, but I'm hoping this issue with the navigation block is resolved before I feel the need to figure that out... /**
* Set current-menu-item class on link that matches current URL.
*/
export function setCurrentMenuItemClass() {
const menuItems = document.querySelectorAll( '.wp-block-navigation-item' );
if ( ! menuItems.length ) {
return;
}
// Check for .current-menu-item class on any item and stop if found.
for ( let i = 0; i < menuItems.length; i++ ) {
if ( menuItems[ i ].classList.contains( 'current-menu-item' ) ) {
return;
}
}
// Add trailing slash to path if missing.
const url = window.location.href.endsWith( '/' )
? window.location.href
: `${ window.location.href }/`;
// Check for matching URL path on any child link of menuItems.
for ( let i = 0; i < menuItems.length; i++ ) {
const link = menuItems[ i ].querySelector( 'a' );
const linkURL = link.href.endsWith( '/' )
? link.href
: `${ link.href }/`;
// Note: link.href returns full URL, even if it's a relative link.
if ( linkURL === url ) {
menuItems[ i ].classList.add( 'current-menu-item' );
}
}
} |
@cr0ybot Thanks for sharing your code. |
+1 on this one, definately needed. just have to build custom links now for this. |
+1 this is missing! I'm currently moving from custom theme to block theme and migrating menus is failing on this kind of links too. |
Did this get picked up for 6.3? Didn’t see anything in the notes. |
It didn't get address in the 6.3 cycle unfortunately. Contributors are looking at priorities for 6.4 now based on capacity. As always PRs are always welcomed. |
+1, definitely needed! |
+1 Just ran into this. I have a few CPTs which need the archive/child pages to be menu item/sub-menu items respectively. |
+1 |
+1 |
I have the same problem. |
I had a similar issue with missing the 'active' class on menu items because they weren't available to add in the Menus screen. Based on @cr0ybot 's JS, I adjusted the function a bit so that it's just based on path. The This fixed my initial issue and also actually helped out on a separate header navigation/project where I always needed the parent menu item 'active' if on a 'child' post/page.
|
Steps to complete this work:
This work could be split into PRs for:
Prior art for this in Classic Menus (not using REST API) can be used as a basis for some of the code. |
I had a PoC for this locally, so I got the ball rolling here with #66821 |
As of today this still doesn't seem to work and we're reaching 2025, I'm using the latest version of WordPress and the Five theme, without any plugin, and the menus are not selected depending on the page I'm on. |
What problem does this address?
Currently you cannot add a Post Type Archive link to the Navigation block. However you can do this via the currently Menus screen.
Here's how you add a Post Type Archive to a menu.
What is your proposed solution?
Add a
post-type-archive
block variation for thecore/navigation-link
block. We'll also need to add test coverage for this in the navigation editor.The text was updated successfully, but these errors were encountered: