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.


Step 2: Creating another menu for pages only. Navigate to Appearance > Menus and create another menu for your 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.




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

10 Discussion to This Post

  1. Hi, thank you for this tutorial! I am just having a little problem with the implementation. I want the menu for the home pages (with the anchors) on the HOME only. I made another menu that I use in the footer, and I would like to use this on the pages. It doesn’t seem to work, so I would like to know if I should have the menus point to a certain location, eg the Header Menu and the Footer Menu. I don’t want to use the Before Header Menu.
    Hope you can help me out. Thank a lot!!

    • If you share the wp-admin access via contact page, then I can help you.

  2. 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().

  3. 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’) ) )

  4. 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


Leave A Reply

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