[wp-trac] [WordPress Trac] #63261: Menu items incorrectly marked as current when page and taxonomy share the same object_id
WordPress Trac
noreply at wordpress.org
Thu Apr 10 20:56:34 UTC 2025
#63261: Menu items incorrectly marked as current when page and taxonomy share the
same object_id
---------------------------------------------+-----------------------------
Reporter: nuadagency | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 6.7.2
Severity: minor | Keywords:
Focuses: accessibility, coding-standards |
---------------------------------------------+-----------------------------
== Description ==
If a page and a taxonomy term (e.g., product_cat) share the same numeric
ID, both can be incorrectly marked as active in menus (current-menu-item,
aria-current="page").
This occurs because WordPress checks only the object_id when determining
the active menu item, without verifying that the object types match.
== Steps to Reproduce ==
Create a WordPress page (e.g., "About") — assume it has ID 23.
Create a WooCommerce product category that also ends up with term_id = 23.
Add both items to a navigation menu.
Visit the product category archive (/product-category/boots/).
Observe that ''both'' menu items ("About" and "Boots") are marked as
current.
== Expected Result ==
Only the menu item representing the current object type (e.g., the product
category) should be marked as current.
== Actual Result ==
Both items are incorrectly highlighted due to ID match, even though they
represent different object types.
== Cause ==
In wp-includes/nav-menu-template.php, this comparison is made:
{{{php if ( $menu_item->object_id === $queried_object_id ) {
$menu_item->current = true; } }}}
This does not check if the object type (e.g. page, product_cat) also
matches.
== Proposed Fix ==
Enhance the condition to ensure both ID and object type match:
{{{php $queried_object_type = ''; if ( isset( $queried_object->post_type )
) { $queried_object_type = $queried_object->post_type; } elseif ( isset(
$queried_object->taxonomy ) ) { $queried_object_type =
$queried_object->taxonomy; } if ( (int) $menu_item->object_id === (int)
$queried_object_id && $menu_item->object === $queried_object_type ) {
$menu_item->current = true; } }}}
== Environment ==
WordPress 6.7.2
WooCommerce 9.7.1
PHP 8.2
== Notes ==
This issue causes confusing menu behavior and accessibility
inconsistencies. It's especially common with WooCommerce where term IDs
frequently overlap with page IDs.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63261>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list