Code To Add New Navigation Menus to Your Theme - WPTRINITY

Code To Add New Navigation Menus to Your Theme

Default WordPress allows theme developers to define navigation menus and then display them.
Add below code in your theme’s functions.php file to define a new menu location in your theme.

function wpe_custom_new_menu() {
  register_nav_menu('my-custom-menu-wpe',__( 'My Custom Menu wptrinity' ));
}
add_action( 'init', 'wpe_custom_new_menu' );

You can now go to Appearance » Menus and you will see ‘My Custom Menu’ as theme location option.

now go to Appearance » Menus and you will see ‘My Custom Menu wptrinity’ as theme location option.

Now you need to add this code to your theme where you want to display navigation menu.

<?php
wp_nav_menu( array( 
    'theme_location' => 'my-custom-menu-wpe', 
    'container_class' => 'custom-menu-wpe-class' ) ); 
?>