Change menu per page with custom theme locations
-
Hello, I’m trying to make new functonality on my website. Theme is Responsive Theme by cyberchimps.
I was using header_menu location as defult, but now I need to upgrade my menu. I need to change menu to another on all school pages.
I have to use custom locations because I have two languages on my website (new menu for each language).I’ve registered two custom theme locations with this code:
register_nav_menus( array( "school_menu" => "School Menu", "agency_menu" => "Agency Menu", ) );
I created menus and links from Admin > View > Menu for each location, and I’have inserted this code in header.php of my child theme:
<?php if ( is_page(54) || "54" == $post->post_parent ) { // the page is "School", or the parent of the page is "School" wp_nav_menu( array( "container" => "div", "container_class" => "main-nav", "fallback_cb" => "responsive_fallback_menu", "theme_location" => "school-menu" ) ); } else { wp_nav_menu( array( "container" => "div", "container_class" => "main-nav", "fallback_cb" => "responsive_fallback_menu", "theme_location" => "agency-menu" ) ); } ?>
instead of default code:
<?php wp_nav_menu( array( "container" => "div", "container_class" => "main-nav", "fallback_cb" => "responsive_fallback_menu", "theme_location" => "header-menu" ) ); ?>
After refreshing page there was no custom menu, only old header menu.
I found a field “Header menu” on Admin > View > Menu > Locations, where i selected nothing.And after refreshig page again I’ve got all pages of my website in my menu and no menus from custom theme locations.
I think the problem is with ocerwriting theme locations configurations.
I hope you can help me to fix this. Thank you.P.S. Sorry for my English – it’s not my native.
- The topic ‘Change menu per page with custom theme locations’ is closed to new replies.