How to register menus for your wordpress theme

How to register menus for your wordpress th

Hello friends, today I’m going to show you how to register menus for a WordPress theme. Most of popular and premium themes have menu setup option and it help user to create menus( sometimes theme support multiple menus ) easily from WordPress back-end. To do this, we have to add few lines of code in functions.php page. It’s very simple.Have a look –

Go to functions.php page in to theme folder. Open it using any text editor and write following codes in there.

function register_my_menus() {

    register_nav_menus(array(
        'top-menu' => 'Top Menu' ,
        'main-menu' => 'Main Menu'
    ));

}

add_action('init' , 'register_my_menus');

How it work?

Here we create a new function called “register_my_menus” and then add another WordPress function called “register_nav_menus”. This “register_nav_menus” function takes an array as parameter. In that array, we’ve defined no of menus according to our need. In this example we are going to add 2 menus.

Now, we are going to call those 2 menus as “top menu” and ” main menu”. Generally, top menu set at the starting of page and main menu set just below the logo. But it can be differ from theme to theme.

We need to setup id for each menu and it must be unique. Finally, we run this “register_my_menus” function when WordPress site loaded. That’s it. If you did everything properly, then you can see “Menus” link in your WordPress theme section.

Register menu demo

I hope this snippet will help you to register menus in your WordPress theme.

Enjoy!

Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!

Tags:  

Share It

Related Posts