WordPress, the famous blogging platform, provides a lot of options for you to work easily with your content. Navigation Menu is one such theme feature which helps to customize navigation menu in your theme. This feature was introduced along with the version 3.0 of WordPress and is a very useful functionality.

WP_NAV_MENU Function

The wp_nav_menu is nothing but a navigation menu. You can locate the menu builder under the Appearance menu item in the WordPress admin. Under the Menus Panel you can create and organize your menus using the drag and drop interface. The wp_nav_menu is a new native menu function that allows you to completely customize all your menus in an easy manner through the admin. The code of the menu is displayed as, “<?php wp_nav_menu(); ?>”. The wp_nav_menu also accepts arguments from the arguments list available in wordpress codex. Some of the important parameters or options used through the wp_nav_menu are discussed below:

  • Theme Location: Theme Location is nothing but the location of the menu in your theme structure. You can actually define a theme location using this parameter, which helps you to set a menu to work in a part of your theme. By using this you can avoid manual work to decide as to which menu should appear where in your theme. If a theme location is not assigned then it would display atleast one item that is assigned to the menu parameter or the first non-output menu or output of the function given by fallback_cb parameter or nothing at all.
  • Menu_class: Menu is a manually defined parameter which defines what should be used. A menu_class is a CSS class used for dropdown menus.
  • fallback_cb: This is a WordPress function which is used when the wp_nav_menu is not available. Default for fallback_cb function is wp_list_pages().
  • container_id and container_class: By default your menu will be wrapped in a div. The container_id and container_class are nothing but the CSS id and class used for div surrounding the navigation.
  • Menu: It is a manually defined parameter that accepts id, slug or a name.
  • Container: The div and nav tags are used to wrap the ul, which is referred to as container.
  • menu_id: The menu_id is applied to the ul element which encloses the menu items.
  • Echo: Returning the menu or to echo the menu you can just use the value ‘0’.

Adding a wp_nav_menu

Firstly you will have to register your menu using register_nav_menu or register_nav_menus. After creating you will have to initialize the menus using the wp_head() hook. You can now display the menus using the wp_nav_menu. The menu is usually displayed below the header. Finally you can style your menu.

Creating a Menu

Creating a WordPress navigation menu is very easy now. You can create a menu from the WordPress plugin by following the steps listed below:

  • Go to WordPress Admin > Appearance > Menus.
  • Type your menu name and click on Create Menu. You can see a message “The sample_menu_name menu has been successfully created”.
  • You can add custom links, pages or categories to your menu.
  • Finally, you can now save the menu you have created in the main menu combo box under Theme Locations.

Plugins for Better Navigation

You can have a better navigation system in your WordPress blog by either working on the coding of the wp_nav_menu function reference or by opting for the predefined WordPress plugins for navigation. These WordPress Plugins for navigation can be broadly classified into two categories as listed below:

  • Plugins for Front End Navigation
  • UberMenu: Present a good range of customizable and creative mega menu configurations.
  • Dropdown Menu Widget: Create horizontal or vertical drop down menu of Pages or Categories or Custom Navigation Menus.
  • Multi-X Bar:  Create a good user-friendly environment by placing function modules in addition to the navigation menu.
  • Plugins for WordPress Menu Management
  • CMS Tree Page View: Add, Edit, View and Search Pages straight from the CMS-like tree overview of your pages and posts.
  • My Page Order: Set the order of your pages through a drag and drop interface.
  • WordPress Hide Admin Menu Page: Set a simple version of your page by hiding all the admin menu and admin bar items, which are not necessary to your users.

The wp_nav_menu function changes the way you look at navigation menu. This is a very useful plugin which gives you the control over your menu items to be displayed. WordPress Navigation Menu is just a smart menu handling plugin which is useful for those who have a lot of items in the menus.

Leave a Reply

Your email address will not be published. Required fields are marked *