For Contact & Get Support From Developer: Click Here

How to register menus for your wordpress theme

Home / How to register menus for your wordpress theme

How to register menus for your wordpress theme

Hello friends, today we are going to learn how to register menus for your WordPress theme. Most of popular and premium theme have menu setup options and it help user to setup menu options easily from WordPress back-end. But to do this we need to add few lines of code in functions.php page. It’s very simple.Have a look –

Go to functions.php page in your theme folder. Open it 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');

Here we create a 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, where we can define no of menus according to our need.

Now, I assume that we need 2 menus and we called them “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.

Now, 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.

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

Enjoy!

Share It

Comments are closed!.