Sarathlal N

Create custom menus for WordPress themes

We can easily make & use new custom menus in our WordPress themes. Now I just walk through on different stages in this process.

First we want to register our new menu in our theme’s functions.php file.

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

Then to display this menu, we want to tell the theme where we like the menus to show up. It may be any template file like header.php, footer.php etc according to our design.

So just add a line of code in appropriate file to show this new menu in our pages.

<?php wp_nav_menu( array( 'theme_location' => 'my-menu' ) ); ?>

If you like some wrapper for our new menu, just add an additional array element with this WordPress function.

'my-menu', 'container_class' => 'my_extra_menu_class' ) ); ?>

Now our new menu is wrapped within a container with a class named as my_extra_menu_class.

Same way, making multiple custom menus is also too simple.

function register_my_menus() {
 register_nav_menus(
 array(
 'header-menu' => __( 'Header Menu' ),
 'extra-menu' => __( 'Extra Menu' )
 )
 );
}
add_action( 'init', 'register_my_menus' );

Need Help?

Do you need any help on WordPress? I'm happy to help you.

Contact Me

Recent Posts

  1. Get variation product data on selecting variation options - WooCommerce
  2. Add TinyMCE WYSIWYG (Rich text area) meta box - WordPress
  3. Reorder product tabs in single product page - WooCommerce
  4. Download webpage for offline reading - wget
  5. Remove product tabs in single product page - WooCommerce

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch.