Add a new navigation menu in WordPress theme

Adding a new navigation menu in WordPress can be done easily by hooking into init action .

First, in your theme's functions.php, you need to write a custom function to register the names of your menu.The menu created will appear in the Appearance -> Menus admin screen.

Adding a new navigation menu in WordPress

function register_my_menu() {
  register_nav_menu('header-menu',__( 'New Menu' ));
}
add_action( 'init', 'register_my_menu' );

The above created menu would appear in the "Theme Locations" box as "New Menu".

Once you've done that, your theme will be modified to use the custom menu we built. The final step is to use and apply the menu to show where you want to display . You can apply this procedure in the relevant custom theme of your project.For example, you might want our custom built menu menu to be inside header.php. So open up that header.php file in the theme editor, and locate where you want to place your menu. and copy paste the below code whereever you want the menu to be displayed

wp_nav_menu( array( 'theme_location' => 'header-menu' ) );

All you need to make sure is that the theme_location points to the name you provided for your menu in the functions.php code above used.To complete the process, if you want to use the custom class to which the menu is wrapped into.use the below code and apply the menu

wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' => 'menu_extra_class' ) );

So menu_extra_class so that you can work with that in CSS and style whatever you like depending on WordPress theme.

custom,theme development,wordpress