I'm trying to get the current-menu-item-id
in any page.
I have used this solution, that brings me very close to the solution.
The problem I have is, that the function below is going through all the menus on the page, and not only the one specific menu, that I want it to go through:
add_filter( 'wp_nav_menu_objects', 'wpse16243_wp_nav_menu_objects' );
function wpse16243_wp_nav_menu_objects( $sorted_menu_items )
{
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->current ) {
$GLOBALS['wpse16243_title'] = $menu_item->ID;
}
}
return $sorted_menu_items;
}
...which means that if you link to the same page more than once in your menus, you can risk that this function returns the current-menu-item-id
from the wrong menu.
Is there any way that I can limit this function to only go through a specific menu and not all menus?
I tried to pass the specific menu items in the variable/parameter $sorted_menu_items
, but that seems not to work.