0

Is it possible to have multiple menus in same location but on different pages. My pages are now:

cars
--car details
--car specs
motorbikes
--motorbike dealers
--map
--contact

Plus about 20 other pages with similar parent & child pages. Now on my site I have one place for navigation (registered as main-nav). What I would like to show in this menu location is different navigation depending on which page user is. If user is on cars and some child page then we should CARS menu in main-nav location and if on motobike dealers page, then we would MOTORBIKES menu in same main-nav location.

It seems that I can place only one menu in one location but is there way around? I could just print always all child pages but the case is that admin needs to be able to select which pages are shown in each menu. Also I have thought about created multiple navigation locations but this is bit tricky because admin adds new pages by time so it would always need changes in template/code level which is not preferred.

All help is appreciated.

1 Answer 1

1

Create multiple menus for each parent page and use an if condition to test which is the parent page and output that particular menu.

You could keep the menu names the same as the parent page names so that any future pages created with new menus will still work.

empty( $post->post_parent ) ? $post_parent_name = get_the_title( $post->ID ) : get_the_title( $post->post_parent );
wp_nav_menu( array(
'menu' => $post_parent_name
));

not tested but something along those lines should work. Hope this helps

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.