wordpress 3.0

Adding WordPress 3.0 Menu Support

Every few months I seem to do the same thing. I’m using a WordPress theme that doesn’t have  WordPress 3.0+ menu support. I want to add it and somehow spend a few too many minutes hunting around for the correct implementation for WP 3.0 menus. So, as much for my own sake as for anyone else’s, here’s the quick and dirty on getting those menus in there.

It’s real easy, at the basic level.

Step 1

Open your functions.php file and add (anywhere inside the main <?php open and ?> close tags, and not interfering with your other code. Just choose a blank spot!) the following:

add_action( 'init', 'register_my_menus' );

function register_my_menus() {
	register_nav_menus(
		array(
                        'primary-menu' => __( 'Primary Menu' ),			
                        'upper-menu' => __( 'Upper Menu' ),
			'lower-menu' => __( 'Lower Menu' ),
		)
	);
}

That’s going to add “opportunity” for 3 menus. If you want to add only one, include only the first

'primary-menu' => __( 'Primary Menu' ),

line. But, I figure, why not add support for 2 more, just in case you want to create them later in your theme.

 

Step 2

Now, open the theme file that will contain your menu. Usually, this is header.php. You should be able to just find the existing menu code and delete it, making space for your new menu. In place of the old menu, insert the following:

<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>

See how ‘primary-menu’ matches the line with ‘primary-menu’ in the functions.php? Good! Now,  in your WordPress Admin, under Appearance / Menus,  name and create a new menu. Then, in the “Theme Locations” box, assign your new menu to the “Primary Menu” slot.

And that should do it! Learn more at this well written and more in depth article, “Goodbye Headaches, Hello Menus!”.

About the Author

Tobias CarrierTobias Carrier is lead designer and owner here at Rogue EasyWeb. He has been a freelance web designer / developer for over 8 years now. If Tobias isn't behind the computer you can find him out on a mountain bike, snowboard or just hiking around.View all posts by Tobias Carrier →