How to register and display a custom navigation in WordPress?

WordPress navigation

Adding custom navigation to your own WordPress theme is simple. You do not need any advance skill to do it yourself.

The only pre-requisite to accomplish this is to know where your functions.php is located.

The functions.php is located in your themes folder inside your WordPress project. That is in wp-content/themes/THEMENAME/functions.php.

Step 1: Add function THEMENAME_custom_new_menu() in your functions.php


function THEMENAME_custom_new_menu() {
     register_nav_menu('primary-menu',__( 'Primary Menu' ));
}
add_action( 'init', 'THEMENAME_custom_new_menu' );
?>

Note: THEMENAME is user-defined. You may change this anytime.

Step 2: Print your menu anywhere in your theme file (e.g. in your index.php or page.php


     'theme_location' => 'my-custom-menu',
     'container_class' => 'custom-menu-class'
) );
?>