0

I want to get current menu id and i was able to find out some solutions for this like
How to get current-menu-item title as variable?
How to get current page menu item name instead of full menu item list

I implement this code but it does not work when i have same term or page multiple time in my menu. For Example i have Asia (term) in my menu twice and it always return id of its first occurrence. I check this in source code and both these menu elements (Asia) are assigned with current-menu-item class. So in this case how i can get correct menu id with multiple occurrence.
Your help will be much appreciated. Thank you!

6
  • I'm not quite sure what you mean exactly. If you have Asia in your menu twice, both menu items will have the same $menu->object_id which is the page ID. Which "ID" are you looking for exactly?
    – Howdy_McGee
    Commented Nov 1, 2017 at 15:17
  • I am looking for menu id not for the page id. Menus are assigned with different id's in back end and even on front end i can see different menu id in source code.
    – wplearner
    Commented Nov 1, 2017 at 15:21
  • So if I have this correct, you're trying to get the Menu ID by finding a specific item in that menu. Would it be easier to use theme_location than trying to get menus by items, which could have duplicates in it?
    – Howdy_McGee
    Commented Nov 1, 2017 at 15:23
  • @Howdy_McGee thank you for your suggestion but i want to get id of currently active menu. Above mentioned solutions work perfectly but when i have one term or page multiple time in my menu then it always return id of first occurrence of that particular term or page.
    – wplearner
    Commented Nov 1, 2017 at 15:29
  • You want to have this identifier in which action or filter ?
    – mmm
    Commented Nov 1, 2017 at 16:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.