Skip to content

Apply 'wp_nav_menu_objects' filter after context class resolution#95

Merged
Log1x merged 1 commit into
Log1x:masterfrom
Reinpal:fix/wp-nav-menu-objects-filter
Feb 21, 2026
Merged

Apply 'wp_nav_menu_objects' filter after context class resolution#95
Log1x merged 1 commit into
Log1x:masterfrom
Reinpal:fix/wp-nav-menu-objects-filter

Conversation

@Reinpal

@Reinpal Reinpal commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

This applies the wp_nav_menu_objects filter after _wp_menu_item_classes_by_context() in MenuBuilder::filter(), matching the behavior of WordPress core's wp_nav_menu().

Any plugin that hooks into wp_nav_menu_objects to fix or augment active states now gets to run.

The most common case is WooCommerce, which hooks into wp_nav_menu_objects via wc_nav_menu_item_classes() (here) to mark the Shop page as current-menu-item when is_woocommerce() is true.

Resolves #25

@Log1x

Log1x commented Feb 19, 2026

Copy link
Copy Markdown
Owner

Appreciate the PR! Would you mind dumping and sharing output before/after of a site with WooCommerce menu items?

@Reinpal

Reinpal commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, sure. Here's the output on /shop/wc_get_page_id('shop') returns 10.
Before (without wp_nav_menu_objects filter)

{
  "active": false,
  "activeAncestor": false,
  "activeParent": false,
  "classes": false,
  "dbId": 53,
  "label": "Shop",
  "object": "page",
  "objectId": "10",
  "url": "https://johanneshof-reinisch.test/shop/",
  "children": []
}

After (with wp_nav_menu_objects filter applied)

{
  "active": true,
  "activeAncestor": false,
  "activeParent": false,
  "classes": false,
  "dbId": 53,
  "label": "Shop",
  "object": "page",
  "objectId": "10",
  "url": "https://johanneshof-reinisch.test/shop/",
  "children": []
}

objectId: "10" matches wc_get_page_id('shop') — WooCommerce's wc_nav_menu_item_classes() correctly sets active: true on the Shop menu item via the wp_nav_menu_objects filter. Without the filter, active stays false even on the Shop page itself, because WooCommerce renders it as a post_type_archive('product') and core's _wp_menu_item_classes_by_context() doesn't recognize the page-type menu item as current in that case.

@Log1x Log1x merged commit 3af8ff5 into Log1x:master Feb 21, 2026
2 checks passed
@Log1x

Log1x commented Feb 21, 2026

Copy link
Copy Markdown
Owner

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WooCommerce Shop page is never active

2 participants