Different Primary Menu on Pages using Altitude PRO Theme

I did this by following steps:

Step 1: First creating a default primary menu. Navigate to Appearance > Menus and create a default primary menu for your site. Check the “Primary Navigation Menu” checkbox and save this menu.

default-primary-menu-altitude-pro

Step 2: Creating another menu for pages only. Navigate to Appearance > Menus and create another menu for your pages.

menu-for-pages

Step 3: Now add this simple code in functions.php file

function gd_nav_menu_args( $args ){
	if( ( 'primary' == $args['theme_location'] ) && is_singular('page') )
	{
		$args['menu'] = 'Menu for Page'; // Add your menu name here. My case it is "Menu for Page"
	}

	return $args;
}

add_filter( 'wp_nav_menu_args', 'gd_nav_menu_args' );

is_singular('page') conditional tag will return true when user is visiting a page. You can change this conditional tag as per your requirement.

Result

home

new-menu-on-page

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

7 Discussion to This Post

  1. If I only want a certain menu to display on the home page, would I use? I’m using it, but it doesn’t seem to be switching the menu on the home page.

    function gd_nav_menu_args( $args ){
    if( ( ‘primary’ == $args[‘theme_location’] ) && is_home() )
    {
    $args[‘menu’] = ‘Landing Page Menu’; // Add your menu name here. My case it is “Menu for Page”
    }

    return $args;
    }

    add_filter( ‘wp_nav_menu_args’, ‘gd_nav_menu_args’ );

    • Is ‘Landing Page Menu’ your menu name? Double check it.

      Also if you are using the static page as a front page then you will change is_home() with is_front_page().

  2. Thank you , for the sweet trick

    worked great after adding “post” into each “is” statement

    if( ( ‘primary’ == $args[‘theme_location’] ) && ( is_archive(‘post’) || is_singular(‘post’) ) )
    {

  3. Really Cool function,

    hoping you could add how i might use for both archive and post function above

    am i close?

    function gd_nav_menu_args( $args ){
    if( ( ‘primary’ == $args[‘theme_location’] ) && is_archive(‘post’) )
    if( ( ‘primary’ == $args[‘theme_location’] ) && is_singular(‘page’) )
    {
    {
    $args[‘menu’] = ‘Menu for Post’; // Add your menu name here. My case it is “Menu for Page”
    }

    return $args;
    }

    add_filter( ‘wp_nav_menu_args’, ‘gd_nav_menu_args’ );

    • I think that this is wrong

      if( ( ‘primary’ == $args[‘theme_location’] ) && is_archive('post') )
      if( ( ‘primary’ == $args[‘theme_location’] ) && is_singular('page') )
      {
      

      You should try this

      if( ( 'primary' == $args['theme_location'] ) && ( is_archive() || is_singular('page') ) )
      {
      

      If you have custom post type then you will try is_post_type_archive() function

Trackbacks

Leave A Reply

Your email address will not be published. Required fields are marked *