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:
function register_my_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' ),
'tertiary-menu' => __( 'Tertiary 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:
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!”.




Comments are closed on this post.