-
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
Navigation block: Add current-menu-item class for post type archive #57808
Navigation block: Add current-menu-item class for post type archive #57808
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Gierand. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
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.
This works as expected and is a great addition :) Thank you for handling this case <3
Thank you. That final test is also passing now so I will merge it. |
What?
When a post type archive is added as a link in the navigation block, and it is the current page, the
current-menu-item
CSS class is missing from the<li>
element.It means that the item can not be styled like other current menu items.
This PR adds a condition that checks if the page is a post type archive, and if the menu item link matches the archive link.
It sets the variable
$is_active
to true. The variable is then used to add the CSS class.Closes #46090
Testing Instructions
Enable a custom post type which has archives enabled. (I used Yoast test helper).
In a site wide template part, create or edit a navigation block and add two links to the archive:
One as a custom link, the other as a link in a submenu.
Go to the front of the website and view the archive page for the post type.
Locate the links to the archive page in the navigation block.
Confirm that the list elements have the
current-menu-item
CSS class.