Aweber - Email Marketing Made Easy
How to Use WordPress Navigation Menus in Thesis

How to Use WordPress Navigation Menus in Thesis

February 26, 2011 · 18 comments

in Thesis

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:

WordPress Navigation Menu in Thesis

Step 2: Build The Menu

Now you can begin building your menu as follows:

  1. Give your menu a name and click “Save Menu”
  2. Add pages, categories and/or custom links to your menu using the sections on the left.
  3. You can re-order the list by simply dragging and dropping the list items
  4. To create child pages, just drag the list item slightly to the right until it snaps into place
  5. 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.

WordPress Navigation Menu in Thesis

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');

Was this post helpful? Consider subscribing to my blog via RSS or

This Site Runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced user, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 18 comments… read them below or add one }

martin February 28, 2011 at 6:11 am

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.

Reply

Thesis-Blogs.com February 28, 2011 at 9:25 am

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.css file:

.menu li { float: none; }

Thanks for commenting.

Reply

martin February 28, 2011 at 12:53 pm

Hey, that’s very very useful, thanks for the tip! : )

Reply

Thesis-Blogs.com February 28, 2011 at 12:54 pm

No problem!

Reply

Jodi March 1, 2011 at 5:31 pm

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

Reply

Thesis-Blogs.com March 1, 2011 at 5:45 pm

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!

Reply

niki March 12, 2011 at 5:29 pm

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

Reply

Thesis-Blogs.com March 12, 2011 at 5:49 pm

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');

Reply

niki March 12, 2011 at 6:07 pm

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

Reply

Thesis-Blogs.com March 12, 2011 at 6:14 pm

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.

Reply

Ashley March 25, 2011 at 12:53 pm

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

Reply

Thesis-Blogs.com March 25, 2011 at 1:00 pm

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.

Reply

Ashley March 25, 2011 at 1:06 pm

So it DOES! Thanks. Ha.

Reply

niki March 27, 2011 at 6:31 am

How would add the secondary menu to more than one page?

Reply

Thesis-Blogs.com March 27, 2011 at 9:15 am

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.

Reply

niki March 27, 2011 at 11:31 am
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?

Reply

Thesis-Blogs.com March 27, 2011 at 11:45 am

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.

Reply

Cecil September 14, 2011 at 11:20 pm

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.

Reply

Leave a Comment

When commenting, you can use basic HTML tags. If you are pasting in any code, please escape it here and then include that code within <pre></pre> tags. Thanks!

CommentLuv badge

Previous post:

Next post: