-
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
current-menu-item does not get applied to custom links in navigation block #61266
Comments
I replicated the issue and can reproduce it by following the instructions above. I tested this using a fresh WP installation with WP version 6.5.2 and using Twenty Twenty Four theme. Watch this when adding menu using "custom link":- https://share.zight.com/E0ueEXKD And this what will happen, when I added a menu item not using the "custom link" feature, it shows this |
I can replicate this issue and have the same problem. When I add a menu item to the navigation in Site Editor, if the item is a custom post type, the menu item does not get the |
For anyone facing this issue, I have added this filter to functions.php as a fix. Replace
|
Hi, |
I've reviewed this and in WP 6.7 when you add a link to the Navigation block using the
However, if you type the URL out (or copy/paste) manually then it will persist as a custom link and not be annotated as a
Video demonstrating different link typesScreen.Capture.on.2024-11-21.at.09-36-29.mp4For the later scenario WordPress cannot "know" that this is an internal link without doing an operation similar to that shown in the comment above. As a result no "current" class will be applied. We could implement something like this but it would have to be run on every single custom link in the Navigation which might have performance implications. Given the way the Navigation block now defaults to inserting the "page" variation of the Navigation Link block, I feel it's increasingly unlikely that users will be linking to internal pages using the custom link variation. The only scenario I can envisage is the need to accommodate internal links such as Therefore I propose that we upgrade the Link UI to accommodate the ability to link to internal anchor points. If there are any other work flows that I'm missing I'd be grateful if folks could let me know below in the comments 🙏 What do you think of the proposal above? |
As I mentioned when I opened this ticket, the pre-baked nav items in Gutenberg are not comprehensive of every possible kind of internal link that could be created. There is, for example, no block for a custom taxonomy term archive. Now perhaps it also resolves in some intelligent way (like your Page example) with more recent versions of the editor - I haven't checked. But I would offer that as another use case.
Classic theme navigation handled this without issue. Obviously, I'm not working on this feature, so there are nuances I don't understand, but it seems like that logic should have been maintained. |
|
I can also confirm the same behavior described above with a site I'm currently working on. Also, when a sub-menu item is selected, it appears the parent no longer gets the "current-menu-parent" class? |
WP6.7.2, 2025 Theme, still broken. |
The above code did not work for me. I fixed it with ChatGPT o3-mini-high:
|
Description
I expect custom links within the navigation block to get the
current-menu-item
class when on that link on the site, as was the case for classic nav menus. Currently, they do not receive this class.Step-by-step reproduction instructions
current-menu-item
classFor quick reproduction, these steps are a bit absurd. The issue is more reasonably encountered when, for instance, you have a custom taxonomy. The prepared nav blocks (like Category Link or Tag Link or Page Link) do not include custom taxonomy term archive links, so you must use a Custom Link item, and the correct classes are not applied in that scenario, either.
Screenshots, screen recording, code snippet
No response
Environment info
WP 6.5.2, Gutenberg 18.2.0. Also present w/o Gutenberg
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: