wp_nav_menu – generating only submenu for top menu item if active

I would like to use wp_nav_menu to generate side menu containing only elements that are children of currently selected top level element, or if a child element is selected, display also all element of top leve lelement.

To make it graphical -> top menu will show only 1 level elements:

Read More
Menu item 1
Menu item 2
Menu item 3
Menu item 4

Structure of entire menu looks this way:

Menu item 1
 Submenu item A
 Submenu item B
Menu item 2
 Submenu item C
 Submenu item D
 Submenu item E
Menu item 3
 Submenu item F
 Submenu item G
 Submenu item H
Menu item 4

Now if current page is one of: Menu item 1, Submenu item A, Submenu item B – side menu shows:

Submenu item A
Submenu item B

If current page is one of: Menu item 2, Submenu item C, Submenu item D, Submenu item E – side menu shows:

Submenu item C
Submenu item D
Submenu item E

If current page is Menu item 4, side menu is empty.

Related posts

Leave a Reply