How to retrieve depth of menu into template

how to get the relation between the page and the menu item ? = is
there a WP function telling this page is linked to this menu item
which has or hasn’t a parent

Inside the walker, inside the start_el method (which you mentioned), $item->object_id is the page ID.

Otherwise, you need to pull the menu…

$locations = get_nav_menu_locations();
$nav_items = wp_get_nav_menu_items($locations['your-menu-location']);

… and loop over that array to match up the current page ID with the object_id in $nav_menu data… if I understand you and I am still not sure that I do.

Leave a Comment