Creating locations for navigational menu

Navigation menu locations

Navigation menu locations

WordPress allows navigation menus to be created easily in your dashboard using Appearence->Menus. By going there you can create as many as navigational menus. Navigation menus can be placed either in widgets or in the locations specified by the theme. You can goto Manage Locations to assign menus to locations.  Each theme allows some locations where navigational menus can be placed. Theme locations need to be registered in the functions.php and later in the template files allow menus to be displayed in the registered menu locations.

Register Menu Locations

Open functions.php in your theme folder and register your menu locations with the theme.  This is made possible by register_nav_menus() function. If you want to register single location then you can use register_nav_menu().

 

Now we have 3 menu locations available if you goto Appearence->Menus in admin dashboard.

  1. Header Top Menu
  2. Primary Menu
  3. Secondary Menu

If you create menus in your dashboard that can be placed in the above three locations. But just assigning menu location doesn’t display menus. We need allow in the template files to display menus in menu locations.

Allow menus to be displayed in registered menu locations.

Navigation menus are usually placed in header and footer sections of the page. However you can use them in any of your template pages. It can be placed in the sidebar or in widgets or in any place in the content.  Open your header.php and place the following code. Navigation menus in the theme are placed using wp_nav_menu() function.

If you create a menu and assign it a location called header top in Appearance->Menu then it will be displayed by the above code.

In the same way we can allow menus to be displayed in other menu locations by allowing them in template files like footer.php or sidebar.php.

Leave a Reply