Dec
02
2011Add and Style Custom Navigation Menus in WordPress Using wp_nav_menu
One of the best features in the WordPress 3.x is the ability to add multiple Menus from pages, posts, customs posts types or even just anything as you desire. It’s very easy to first register custom menu in the admin panel and then call in your theme files and style them as you want.
To add a custom Menu option on your theme, add this to your theme function.php file:
if ( function_exists( 'register_nav_menus' ) ) { register_nav_menus( array( 'footer_menu' => 'My Custom Footer Menu', 'portfolio_sidebar_menu' => 'Portfolio Sidebar Menu', 'services_sidebar_menu' => 'Services Sidebar Menu' ) ); } //this will three custom menus options in your WP-Admin menus
Inside your theme file, her;es how you cxall this above menu. Make sure you add some menus items using WP-Admin before calling it. I’m disabling the navigation container div and assignign it a specific class left-sidebar in the arguments to style the menus.
$args = array('container'=>'', 'menu' => 'portfolio', 'items_wrap' => '<div class="left-sidebar">%3$s</div>' ); wp_nav_menu( $args );
Here’s the css for styling:
.left-sidebar { width: 228px; margin:0 auto; list-style-type: none; text-align: center; } .left-sidebar li a, .left-sidebar li a:visited{ display:block; padding-top:1.3em; background:url('images/button.png') center bottom no-repeat; font-size: 18px; color: #ffffff; font-weight: bold; text-decoration: none; height: 58px; margin-bottom: 5px; } .left-sidebar li a:hover{ padding-top:1.3em; display:block; background:url('images/button.png') center top no-repeat; font-size: 18px; color: #ffffff; font-weight: bold; text-decoration: none; height: 58px; margin-bottom: 5px; }
Here’s the button 
Hope that helps.
Cheers!
Related posts:
- Adding Custom Menus in your Theme for WordPress 3.x
- WordPress Custom Post Type Listing by Alphabets with Alphabetical Navigation
- WordPress Custom Post Types – Best Plugin for the Job and How to Set it Up
- Resolve Permalinks 404 Error with Custom Post Type using WordPress
- Custom Page Templates Not Showing Up in Page Attributes Drop Down in WordPress Admin Panel
Stian
I don’t think I did something wrong, but it doesnt show my menu, it just actually prints out the code, and not the menu. Any solutions?
Ali Qureshi
Make sure you add all php code inside php opening and closing tags like this:
Patrick
Hey Ali !
I tried your code:
- at first it didn’t work at all, it seems a ” ; ” is missing when the menu is called:
%3$s’ ) ;
instead of
%3$s’ )
- when this ” ; ” is added, the page then shows up, but it display my main menu as a sidebar, instead of the specific menu I set up.
Sorry i’m a newbie, I must have missed something.
Ali Qureshi
Yes, that indeed was missing., I have updated it. Once you see the menu, you can then change its placement and look and feel anyway you want. For that you must know css.