Last active
July 16, 2024 16:53
-
-
Save gerbenvandijk/5253921 to your computer and use it in GitHub Desktop.
Mark (highlight) custom post type parent as active item in Wordpress Navigation.When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great Gist, thanks to everyone for sharing! Saved me a lot of time!
It did however not work for me with child pages that are an ancestor of a menu item.
I think it's because pages don't have a rewrite slug.
So I checked for pages and populated the ancestors array accordingly
This is the full snippet: