Create Custom Menu in WordPress

Wordpress |

To add a custom navigation menu, the first thing you need to do is register your new navigation menu by adding this code to your theme’s functions.php file.

function wpb_custom_new_menu() { 
register_nav_menu(
‘my-custom-menu’,__( ‘My Custom Menu’ 
)); 
} 
add_action( ‘init’, ‘wpb_custom_new_menu’ );

Tip: If you want to add more than one new navigation menu location, then you would need to use a code like this:

function wpb_custom_new_menu() { 
register_nav_menus( array( 
'my-custom-menu' => __( 'My Custom Menu' ), 
'extra-menu' => __( 'Extra Menu' ) ) 
); 
} 
add_action( 'init', 'wpb_custom_new_menu' );

Next, we need to display the new navigation menu in your WordPress theme. The most common place where navigation menus are usually placed is in the header section of a website just after the site title or logo.

However, you can add your navigation menu anywhere you want.

You will need to add this code in your theme’s template file where you want to display your menu.

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