How to add secondary menu in WordPress.
By default WordPress displays the primary menu as the main menu in most Wordress themes, All new pages are automatically added to this default primary menu. If you need a custom menu or how to add a secondary menu in WordPress, this is how to:
How to add a secondary menu in WordPress
To add a secondary menu in WordPress you should be working with a childtheme. This is how to do it:
- Open the functions.php or create the file if you don’t already have it your childtheme. Add this code to enable a secondary menu in the WordPress admin (don’t forgett the <?php tags if you need to add them):
//add a secondary menu
'primary' => __( 'Primary Menu', 'CHILDTHEMENAME' ),
'secondary' => __( 'Secondary Menu', 'CHILDTHEMENAME'),
- Save and upload the functions.php to your child theme. This will add the choice of a secondary menu in WordPress admin > appearance > menus > manage locations. However, you need to add a custom menu to be able to choose it.
- Add a custom menu in WordPress admin > appearance > menus and choose it to be the secondary menu in WordPress admin > appearance > menus > manage locations.
- To show the menu on your website you need to add this code below somewhere in your child theme, for example in the header.php. Use this php code to show the secondary menu inside a div with class “custom-menu”:
<?php //print the menu
wp_nav_menu( array('container_class' => 'custom-menu',
'theme_location' => 'secondary' ) ); ?>
How to add a custom menu WordPress:
- Log in to the WordPress Admin and go to appearance > menus
- “Create new menu” and name it. Save the menu by clicking the button “create menu”.
- You will see panels on the left: pages / categories / links. Just open a panel for example “pages” to see all created pages on your site (use the “view all” tab). Simply check and “add to menu”.
- To see all panels avalable, use the > “Screen Options” tab on the top-right to also see Tags, Posts and more,
- Create an external link in the panel “Links”.
- Or add a category to the menu using the “Category” panel and so on.
- You can drag and drop all menu items in the menu to suit your needs.
- You can add menu items inside other menu items. this will create a dropdown sub menu.
- When you are done, save the menu.
- To make your custom the default main menu , check the box “primary menu” or go to the “Manage locations” tab. Choose your primary menu and your secondary menu. Save.
You are done!