Okay
  Print

Adding different menus to different pages

Step 1: In your child theme's functions.php file register your new menu items by adding the following:

function ghostpool_register_new_menus() {
    register_nav_menus( array(
        'gp-new-menu-1' => esc_html__( 'New Menu 1', 'aardvark' ),
        'gp-new-menu-2' => esc_html__( 'New Menu 2', 'aardvark' ),
    ) );
        
}
add_action( 'after_setup_theme', 'ghostpool_register_new_menus' );

This create two new menu areas.

Step 2: Now you need to tell the theme to use these menus on specific pages by adding the following to functions.php:

function ghostpool_custom_main_header_primary_nav() {
    $menu = '';
    
    if ( is_page( 123 ) ) {
    
        $menu = 'gp-new-menu-1';
        
    } elseif ( is_page( 456 ) ) {
        $menu = 'gp-new-menu-2';
    
    } else {
        $menu = 'gp-main-header-primary-nav';
    }
                
    return $menu;
}
add_filter( 'ghostpool_main_header_primary_nav', 'ghostpool_custom_main_header_primary_nav' );

This tells the theme to replace the main header primary menu with the menu "gp-new-menu-1" on the page with ID 123 and "gp-new-menu-2" on the page with ID 456. On all other pages it uses the original menu "gp-main-header-primary-nav".

You can do this for any of the theme menus using this method, just replace the filter name in step 2 with the following names:

  • ghostpool_top_header_left_nav
  • ghostpool_top_header_right_nav
  • ghostpool_main_header_primary_nav
  • ghostpool_main_header_secondary_nav
  • ghostpool_profile_nav
  • ghostpool_side_menu_nav
  • ghostpool_footer_nav
  • ghostpool_mobile_primary_nav
  • ghostpool_mobile_profile_nav