One of the new features in WordPress 3.0 is the Menu generator. This lets you create menus containing categories, pages, and links all together. However, many themes have not yet released updates to enable this functionality. In this tutorial, I will show you how to enable your Thesis powered blog to take advantage of the menus feature.
You will need to edit your custom_functions.php. Enter the following lines below all code already there, but above the ?>:
remove_action('thesis_hook_before_header', 'thesis_nav_menu');
add_action('thesis_hook_before_header', 'custom_nav');
function custom_nav() {
if ( function_exists( 'wp_nav_menu' ) ) {
wp_nav_menu( array('container'=>'', 'menu_class'=>'menu' ) );
} else {
thesis_nav_menu();
}
}
add_theme_support( 'menus' );
register_nav_menus( array(
'primary' => __( 'Navigation Menu' ),
) );
Now, let’s explain what this all does:
The first line removes the Thesis call to the built in menu function of Thesis. The second line adds the custom function we will use to access the new WordPress 3.0 menu feature. (In both of these lines, it is assumed that you have your menu bar display at the top of the page, above the header graphic. If yours is below the header, replace thesis_hook_before_header with thesis_hook_header.)
Lines 3-8 are our custom function to display the new menu (called with the function wp_nav_menu). Included here is a check just to make sure that function does exist and use the built in Thesis menu in the case that wp_nav_menu is not there (this helps if you copy the custom functions to a site not yet upgraded to WordPress 3.0).
Line 9 (add_theme_support…) is the line that actually tells WordPress the theme can handle the new menu feature.
The remaining lines register the actual name of the navigation menu so that it displays in your dashboard’s Menu editor. You can add additional menu areas by duplicating lines 2 and 10-12 and replacing the hook area in line 2 (for a reference of hook areas, visit http://thesishooks.com/) and the ‘primary’ and ‘Navigaton menu’ in line 11 with unique names.
One caveat: this will stop the active tab in the navbar from being a different color. You can edit your custom_css to accomodate for this by specifying the class “current”. Note that this will then override the Thesis Design options setting.
Let me know how this works out for you or if you have any questions.
Related posts:
Tags: Thesis, Thesis 1.7, Thesis Hooks, Wordpress 3.0, Wordpress Menu Generator, Wordpress upgrade
