Monday, December 24, 2012

How to Add Custom Navigation Menus in WordPress 3.0 Themes

Custom Navigation Menus feature in WordPress 3.0 will make WordPress even more user friendly for beginners. This function let you organize your menu, create drop down menus, add new items to menu, and much more. The drag-and-drop function of this feature is what makes it extremely easy to use. This feature will not be available in older themes unless the theme author(s) update their themes. In this article, we will show you how you can enable and install custom navigation menus in your themes.
We see this feature as one of the most demanded feature in the future of WordPress themes. Below is a simple screenshot that shows you what you can do with this menu option.
WordPress 3.0 Custom Navigation Menus
You can create multiple menus, add existing categories or pages to the menu, and you can add custom links to menu as well. You can organize the menus and create drop-down menus with a simple drag-and-drop feature.

How to enable Custom Navigation Menus in WordPress 3.0

Like the custom background, header image, and post thumbnails, the custom navigation menus also needs to be enabled through your theme’s functions.php file.
Simply add the code below to your theme’s functions.php file:
add_theme_support( 'menus' );
If this code is not added in your functions.php file, the user will not see this as an option in the Admin panel.

How to Add Custom Navigation Menus in WordPress 3.0 Themes

Once you have enabled the feature, now you can add it in your theme. These menus are not limited for header.php file only. You can add them anywhere you like to fit your design’s need by pasting the code below:
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
The main function as you can see is wp_nav_menu. The arguments we have in the code are sort_column and container_class. The sort_column value tells WordPress to follow the order you pick in the options panel, and the container_class is the css styling class that you pick for this specific menu.
For custom themes: If you are using more than one menu, then you need to specify either the menu ID, menu slug, or menu name. The parameters are: $id, $slug, $menu respectively.

No comments: