If you don’t like to read much, just skip ahead to the code below. I like to ramble sometimes.
So, let’s talk about the WordPress navigation menu system that was introduced around the release of WordPress 3.0.
If you’ve been using Thesis for a while, you will be familiar with how Thesis handles the navigation menu. It’s really easy to add pages or categories to your navigation and change the order if you’d like. You can also have instant drop down menus when you add child pages. However, when you stack this up against the new WordPress menu system, the Thesis menu doesn’t have as many features and the WordPress menu offers a lot more flexibility.
In my experience, it really depends on the project I’m working on as to whether I will use the Thesis navigation menu, or the WordPress menu. In my opinion, here are some of the benefits to using the WordPress menu:
- You can create multiple menus
- You can mix and match between pages and categories and sort them any way you want
- You can easily add arbitrary links to a menu item
- You can assign custom classes to each menu item
- It’s easy to edit and add menu items
- It’s easy to add child pages
Once I started using the WordPress navigation menu I was kinda hooked on it. You just have to get over the learning curve on how to make it work, and more specifically how to make it work in Thesis.
How to use WordPress Navigation Menus in Thesis
I’d like to provide credit here where it’s due. I first learned how to do this from Matt Hodder’s post on enabling WordPress 3.0 features in Thesis. I’m just expanding on it slightly here with a little more detail to the instruction.
Step 1: Add this code to your custom-functions.php file:
add_theme_support('menus');
function new_menu() {
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
}
register_nav_menu('primary', 'Primary Navigation');
add_action('thesis_hook_before_header', 'new_menu');
remove_action('thesis_hook_before_header', 'thesis_nav_menu');
This code will add support for WordPress Menus, it will register a new “primary” menu and then replace the default Thesis menu with a new WordPress menu.
After you’ve added the code, head over to the WordPress Dashboard and click the “Menus” option under “Appearance.” Your screen will look like this:
Step 2: Build The Menu
Now you can begin building your menu as follows:
- Give your menu a name and click “Save Menu”
- Add pages, categories and/or custom links to your menu using the sections on the left.
- You can re-order the list by simply dragging and dropping the list items
- To create child pages, just drag the list item slightly to the right until it snaps into place
- Finally, assign your new menu by selecting it from the drop down box at the top left
Be sure to click “Save” when you’ve completed each step.
How to add more than one menu using WordPress menus
If you would like to add additional menus, it’s really quite easy. In the example below, I am adding two additional menus as follows:
register_nav_menu('secondary', 'Secondary Menu');
register_nav_menu('footer', 'Footer Menu');
You would add this to your custom-functions.php file. This will register these two additional menus. Of course, after you have registered these new menus, you will need go back to the dashboard and build menus for these by following Step 2 above.
How to reference the extra menus and make them show up:
So you’ve registered and built two additional menus, but now we want the Footer Menu for example to show up in the footer. Here’s one way to reference the WordPress menus:
<?php wp_nav_menu( array( 'container_class' => 'footer-menu', 'theme_location' => 'footer' ) ); ?>
You would simply add that code where you want the menu to show up. Since you’re likely working in Thesis, you would attach this code to the applicable Thesis hook as follows:
function footer_menu() {
wp_nav_menu( array( 'container_class' => 'footer-menu', 'theme_location' => 'footer' ) );
}
add_action('thesis_hook_footer','footer_menu');
- WordPress Codex
- Enable WordPress 3.0 Features for the Thesis Theme
- Goodbye, headaches. Hello, menus!
Was this post helpful? Consider subscribing to my blog via RSS or








































{ 18 comments… read them below or add one }
Hi, I’m thinking of using Thesis for my blog. My question is how hard is it to position the main navigation diagonally on the left side of the page (as opposed to the default horizontal nav)
I really appreciate any hints or tips you can give.
Thanks.
Hi Martin,
It’s really easy to reposition the navigation menu in Thesis. You’d just add these two lines of code to a file in Thesis called
custom-functions.php:remove_action('thesis_hook_before_header','thesis_nav_menu'); add_action('thesis_hook_before_sidebar_1','thesis_nav_menu');This will place the menu before the first sidebar either on the left or right side, depending on where your sidebar is positioned. You would also probably want to make this minor css adjustment to the
custom.cssfile:.menu li { float: none; }Thanks for commenting.
Hey, that’s very very useful, thanks for the tip! : )
No problem!
Thanks for the tutorial! I now have two nav menus, but can’t figure out how to format the second one in the custom CSS file? Any advice?
Jodi recently posted..New Car Buying – Should You Get the Extended Warranty
Hi Jodi, thanks for commenting. I highly recommend that you get Firebug. This Firefox addon will allow you to see the css ID’s and classes for the elements on your page that you want to style. In your case, if you’re referring to the second navigation that is below your header, it’s wrapped in a div with the class of “menu-header.” So you will need to add the appropriate css styling to that and the elements within it. If you need help with it let me know through the “Hire Me” link at the top. Thanks again!
Great tutorial, however I got the following error. Also, is it possible to assign different menus to different pages?
Code:
add_theme_support('menus'); function new_menu() { wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); } register_nav_menu('primary', 'Primary Navigation'); add_action('thesis_hook_before_header', 'new_menu'); remove_action('thesis_hook_before_header', 'thesis_nav_menu'); register_nav_menu('secondary', 'Food Menu'); function secondary_menu() { wp_nav_menu( array( 'container_class' => 'food-menu', 'theme_location' => 'food' ) ); } add_action('thesis_hook_after_header','food_menu');Error message:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘food_menu’ was given in /home/nikitc5/public_html/livelocaldecorah.com/wp-includes/plugin.php on line 395
Looks like you’re referencing an incorrect function. You named the function for the second menu “secondary_menu” and you’re referencing it using “food_menu”. That could be the cause. Here’s how I’d write it:
register_nav_menu('secondary', 'Food Menu'); // food menu function food_menu() { wp_nav_menu( array( 'container_class' => 'food_nav', 'theme_location' => 'secondary' ) ); } add_action('thesis_hook_after_header', 'food_menu');See if that makes sense. Then to only show this menu on a certain page, use WordPress conditional tags like this:
// food menu function food_menu() { if ( is_page('123') ) { wp_nav_menu( array( 'container_class' => 'food_nav', 'theme_location' => 'secondary' ) ); } } add_action('thesis_hook_after_header', 'food_menu');deleted all…tried again from the start with the code you gave me:
Got this:
Fatal error: Cannot redeclare food_menu() (previously declared in /home/nikitc5/public_html/livelocaldecorah.com/wp-content/themes/thesis_18/custom/custom_functions.php:104) in /home/nikitc5/public_html/livelocaldecorah.com/wp-content/themes/thesis_18/custom/custom_functions.php on line 111
I just tried this myself and it works perfectly. Delete everything from your custom-functions.php file just to troubleshoot, and insert this code:
add_theme_support('menus'); function new_menu() { wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); } register_nav_menu('primary', 'Primary Navigation'); add_action('thesis_hook_before_header', 'new_menu'); remove_action('thesis_hook_before_header', 'thesis_nav_menu'); register_nav_menu('secondary', 'Food Menu'); // food menu function food_menu() { wp_nav_menu( array( 'container_class' => 'food_nav', 'theme_location' => 'secondary' ) ); } add_action('thesis_hook_after_header', 'food_menu');That works for me. It adds a custom WP menu before the header and then a second custom menu below the header. Make sure you have WordPress menus activated in the Thesis “Site Options” and also that you have built your menus in the “Appearance/Menus” section from the WP dashboard.
This tutorial has helped me a TON! Thank you. Question, how do you get your drop down menu (on this site) to have a different background color than the main nav? I didn’t think that was possible, but I’ve always wanted to be able to do it!
Cheers
Ashley
Happy to hear it has helped you. The drop down menu will have it’s own unique css class. You should get Firebug which will help you target that specific class and then you can write the css to give those elements a different color.
So it DOES! Thanks. Ha.
How would add the secondary menu to more than one page?
Well, you don’t have to do anything for this. When you attach the new menu to an applicable Thesis hook, it will appear on all pages.
register_nav_menu('tertiary', 'Music Menu'); // Music menu function music_menu() { if ( is_page('4'') ) { wp_nav_menu( array( 'container_class' => 'music_nav', 'theme_location' => 'tertiary' ) ); } } add_action('thesis_hook_after_header', 'music_menu');so (is_page(’4′)) is where the menu is now appearing, but I want it to appear on two more pages (but not all pages) as well. how can i make that happen?
You can do this:
register_nav_menu('tertiary', 'Music Menu'); // Music menu function music_menu() { if ( is_page('4') || is_page('1') || is_page('2') ) { wp_nav_menu( array( 'container_class' => 'music_nav', 'theme_location' => 'tertiary' ) ); } } add_action('thesis_hook_after_header', 'music_menu');You might also want to use an array if there are more pages. You can read more about WordPress Conditional Tags.
Hi,
Just wondering how can I create a function to switch from two different menus.
Example:
I have a two menu on top of the header, topmenu1 and topmenu2, if I click topmenu1 their will be another menu show below the header and then when I click topmenu2, different header will show.