How to Display Custom WordPress Menus Using Widgets
You don’t have to use the wp_nav_menu(); template tag in WordPress to display the menus on your site because WordPress also provides you with Custom Menu widgets that you can add to your theme. You can, therefore, use widgets instead of template tags to display the navigation menus on your site. This feature is especially helpful if you have created multiple menus in and around your site in various different places.
Your first step is to register a special widget area for your theme to handle the Custom Menu widget display. To register this widget, open your theme’s functions.php file and add the following lines of code:
// ADD MENU WIDGET if ( function_exists('register_sidebars') ) register_sidebar(array('name'=>'Menu Widget',));
These few lines of code create a new widget area called Menu on the Widgets page on your Dashboard. At this point, you can drag the Custom Menu widget into the Menu widget to indicate that you want to display a Custom Menu in that area. The Available Widget area with the Custom Menu widget displayed is shown.
To add the widget area to your theme, head over to the Theme Editor (Appearance→Editor) and open the header.php file; then add these lines of code in the area you want the Menu widget displayed:
<ul> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Menu Widget') ) : ?> <?php endif; ?> </ul>
These lines of code tell WordPress that you want information contained in the Menu widget area displayed on your site.