How to create a custom menu for each different page
-
Hi! i’ve been googling a lot about this without any success, so i’m giving this a try, hopefully someone have done this before?:)
I want to have different menus displaying for different pages, first of all i just want to make it work with twenty-eleven or the twenty-ten theme.
So, i found an old topic about this where it says:
“First make sure you have registered your menus in functions.php:
//register the custom menus
function register_my_menus() {
register_nav_menus(
array(
‘profile-menu’ => __( ‘Profile Menu’ )
‘services-menu’ => __( ‘Services Menu’ )
)
);
}
add_action( ‘init’, ‘register_my_menus’ );Customise each menu in the wordpress backend.
Then call the relevant menu using an if statement in the sidebar (or wherever you want the menus to appear).<?php
if (is_page(‘profile’)){
wp_nav_menu(array(‘menu’=>’profile-menu’ ));
} elseif (is_page(‘services’)) {
wp_nav_menu(array(‘menu’=>’services-menu’ ));
}
?>
ensure the string in the is_page() function matches the slug (or id) of the page you want to check.”BUT I can’t get it to work, when i insert this function into functions.php it makes wordpress crash, does anyone have any idea of how to do this?
- The topic ‘How to create a custom menu for each different page’ is closed to new replies.