0

There's a lot to read about secondary menus in WP, however it looks like the tricks are for older WP version. I see that WP 4.5 supports multiple menus in the dashboard. What's not clear, once you have made your secondary menu, is how to insert it in theme location (in header for example)

Does it still takes this?

<?php wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'menu_class' => 'topper', 'fallback_cb' => '') ); ?>

Moreover, Do i need to place this code in functions.php?

add_action( 'init', 'my_custom_menus' );
  function my_custom_menus() {
     register_nav_menus(
        array(
  'primary-menu' => __( 'Primary Menu' ),
  'secondary-menu' => __( 'Secondary Menu' )
                )
         );
  }

Last question is: will it be automatically visible in the mobile menu version?

Thans

1

Yes, you need to add this:

add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
 register_nav_menus(
    array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
            )
     );
}

to your functions.php. It will create the menu locations in the menu admin area. More info: https://codex.wordpress.org/Navigation_Menus

In your theme, usually in header, you need to add this line where you want your secondary-menu:

<?php wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'menu_class' => 'topper', 'fallback_cb' => '') ); ?>

More info here: https://developer.wordpress.org/reference/functions/wp_nav_menu/

If you want to customize the menu code you can create a custom walker, you can refer to: https://codex.wordpress.org/Class_Reference/Walker

As for the last question, it should be but it's theme related.

  • Thanks a lot. Adding the action in functions.php will create two additional menus (3 in total with WP default) so I have removed the-primary-menu in the call (In the array only one menu added). The menu items appear as un ul with bullets, proabily I need to format this with CSS. But the worst part is that the secondary menu will not shrink and will not be part of the mobile men. – Riccardo May 20 '16 at 15:38
  • You can do that in different ways. Walkers are quite complex, but you can use wp_get_nav_menu_items and some coding to create a custom menu. developer.wordpress.org/reference/functions/… – flero May 20 '16 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.