You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
current-menu-item does not get applied to custom links in navigation block #61266
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
New WP site (at, say, example.test)
Install TT4
Create new navigation menu via Editor
Add "Custom Link" to navigation using the WordPress install's URL and some slug, such as "http://example.test/link"
Create a new page titled "Link" (or otherwise) so that its permalink matches the menu item you created, such as "http://example.test/link"
Inspect nav menu on website front end
See no current-menu-item class
For 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.
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 aria-current="page". See this: https://share.zight.com/JruE7pEn
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 current-menu-item class applied and does not get the aria-current either.
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
I've reviewed this and in WP 6.7 when you add a link to the Navigation block using the Custom Link variation it will save as type: page if you select from the search results.
<!-- wp:navigation-link {"label":"Custom Link Again","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->
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 page.
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 http://localhost:8888/?page_id=2#someinternalanchor where someinternalanchor is a "deep link" anchor point on the page. We don't support that in the Link UI so that may require users to work around this using the custom link.
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 🙏
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.
WordPress cannot "know" that this is an internal link
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.
yep, that's an annoying bug, manual link does not get the li current-menu-item class nor the aria-current="page" on a:href
"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." sometimes it's quicker to copy the page the url instead of searching for it (ex: WooCommerce product page with too many pages)
yep, the anchor link use case is also another use case
another anyoning thing : if you move your website from preprod to prod, you have to edit all links, the base url is not replaced (perhaps it's another issue, but Dave would like for sure to be aware of this).
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?
Thanks for all the feedback and reproduction folks. It's very much appreciated.
It seems to me that there must be a problem. Directly pasted URLs can be considered separately, but we should certainly solve for the case when someone links to an entity (Post, Page).
I took a quick look at this in regards to entity links (not static URLs):
Root Cause
In packages/block-library/src/navigation-link/index.php (line 214), the code checks if the queried object has a property matching the link's kind:
$is_active = ! empty( $attributes['id'] )
&& get_queried_object_id() === (int) $attributes['id']
&& ! empty( get_queried_object()->$kind ); // ← This might fail for custom post types
This third check likely fails for custom post types because the queried object structure might not match what the code expects. The kind check appears to have been a safeguard against a historical bug where id could be a string URL, but it might now be too restrictive.
Solution
Remove the kind property check and validate that id is numeric:
Remove the ! empty( get_queried_object()->$kind ) check
Ensure id is numeric and positive (prevents the string-URL bug)
This should fix custom post types while maintaining safety against the historical bug. The ID match should be sufficient to determine if we're on the linked entity's page.
We should start with a failing e2e test and work forwards from there.
Possibly useful context: I filed #82380 about how the insertion flow steers people into creating these URL-only links in the first place — the + appender defaults to Page Link, its search only looks at pages, and the Category/Tag Link variations are hidden behind "Browse all", so pasting a URL into the search field ends up being the natural fallback. It doesn't answer the rendering question discussed here, but if the picker created entity links by default, most of the menus hitting this wouldn't exist.
Activity
jhimross commentedon May 10, 2024
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
aria-current="page". See this: https://share.zight.com/JruE7pEnchuckpearson commentedon May 29, 2024
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
current-menu-itemclass applied and does not get thearia-currenteither.jeroensmeets commentedon May 30, 2024
For anyone facing this issue, I have added this filter to functions.php as a fix. Replace
str_ends_withif you're on PHP < 8.github-actions commentedon Jun 30, 2024
Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.
getdave commentedon Nov 21, 2024
I've reviewed this and in WP 6.7 when you add a link to the Navigation block using the
Custom Linkvariation it will save astype: pageif you select from the search results.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
page.Video demonstrating different link types
Screen.Capture.on.2024-11-21.at.09-36-29.mp4
For 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
http://localhost:8888/?page_id=2#someinternalanchorwheresomeinternalanchoris a "deep link" anchor point on the page. We don't support that in the Link UI so that may require users to work around this using the custom link.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?
ethanclevenger91 commentedon Jan 10, 2025
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.
Marc-pi commentedon Jan 26, 2025
voyager131 commentedon Feb 10, 2025
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?
wdburgdorf commentedon Mar 1, 2025
WP6.7.2, 2025 Theme, still broken.
wdburgdorf commentedon Mar 1, 2025
The above code did not work for me. I fixed it with ChatGPT o3-mini-high:
14 remaining items
shazzad commentedon Dec 18, 2025
Reproduction Report
Description
This report validates whether the issue can be reproduced.
Environment
Actual Results
Additional Notes
Steps to Reproduce:
Test post.current-menu-itemclass to the menu item.Supplemental Artifacts
"Test post" single template does not add the css class.
"Block Properties" page link correctly adds the css class to the dom.
getdave commentedon Dec 19, 2025
Thanks for all the feedback and reproduction folks. It's very much appreciated.
It seems to me that there must be a problem. Directly pasted URLs can be considered separately, but we should certainly solve for the case when someone links to an entity (Post, Page).
getdave commentedon Dec 19, 2025
I took a quick look at this in regards to entity links (not static URLs):
Root Cause
In
packages/block-library/src/navigation-link/index.php(line 214), the code checks if the queried object has a property matching the link'skind:This third check likely fails for custom post types because the queried object structure might not match what the code expects. The
kindcheck appears to have been a safeguard against a historical bug whereidcould be a string URL, but it might now be too restrictive.Solution
Remove the
kindproperty check and validate thatidis numeric:! empty( get_queried_object()->$kind )checkidis numeric and positive (prevents the string-URL bug)Updated logic:
This should fix custom post types while maintaining safety against the historical bug. The ID match should be sufficient to determine if we're on the linked entity's page.
We should start with a failing e2e test and work forwards from there.
jhmonroe commentedon Jan 30, 2026
@getdave thanks for your movement on this! who can assign it? def a big thing to fix to aid with adoption from classic themes to FSE
getdave commentedon Feb 6, 2026
We also need to consider the new entity binding that's been added to the nav link block.
getdave commentedon Feb 6, 2026
It's tracked in #38275.
It's open for anyone to pick up and it even has a clear technical insight for people to follow.
It might be possible to look at pre 7.0 but it's not guaranteed.
getdave commentedon Mar 13, 2026
@jeryj would you agree that given that
...we should be ok to remove the
kindcheck and simply check for the presence of an ID that is number-like?Update: actually I realised it is not safe because I think Posts and Terms can have the same ID because they are in different DB tables!
iamtakashi commentedon Sep 3, 2026
Possibly useful context: I filed #82380 about how the insertion flow steers people into creating these URL-only links in the first place — the + appender defaults to Page Link, its search only looks at pages, and the Category/Tag Link variations are hidden behind "Browse all", so pasting a URL into the search field ends up being the natural fallback. It doesn't answer the rendering question discussed here, but if the picker created entity links by default, most of the menus hitting this wouldn't exist.