Skip to content
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

Merged
merged 13 commits into from
Apr 19, 2024

Conversation

carolinan
Copy link
Contributor

@carolinan carolinan commented Jan 12, 2024

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.

@carolinan carolinan added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels Jan 12, 2024
@carolinan carolinan marked this pull request as ready for review January 12, 2024 15:09
@carolinan carolinan requested a review from ajitbohra as a code owner February 14, 2024 07:43
Copy link

github-actions bot commented Feb 14, 2024

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 props-bot label.

Unlinked Accounts

The 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.

Unlinked contributors: Gierand.

Co-authored-by: carolinan <[email protected]>
Co-authored-by: fabiankaegy <[email protected]>
Co-authored-by: Humanify-nl <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@carolinan carolinan requested a review from fabiankaegy April 19, 2024 06:17
Copy link
Member

@fabiankaegy fabiankaegy left a 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

@carolinan
Copy link
Contributor Author

Thank you. That final test is also passing now so I will merge it.

@carolinan carolinan merged commit 4b08cf1 into trunk Apr 19, 2024
62 checks passed
@carolinan carolinan deleted the update/navigation-archive-current-menu-item branch April 19, 2024 08:38
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation block - add 'current-menu-item' to post-type archive links
2 participants