WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I built a navigation menu using the native menu builder in WordPress 3. This is the code I use to render it:

<?php wp_nav_menu( array('menu' => 'Main Navigation','menu_id'=> 'headernav','menu_class'=>'navigate')); ?>

It renders exactly the way I would expect on every page except 404.php. This is how it renders everywhere else:

<div class="menu-main-navigation-container"><ul id="headernav" class="navigate">

and this is how it renders on 404.php:

<div class="navigate"><ul>

And on 404.php it lists out every single page on my site, as opposed to the ones I built into the menu.

Does anybody have any idea why this is happening? Any help is greatly appreciated.


Here is the code from my functions.php file:

function mytheme_setup() {

    register_nav_menus( array(
        'main-navigation' => 'Main Navigation',
        'subnav-navigation' => 'Sub menu nav',
        'how-eli-works-nav' => 'How Eli Works'
    ) );
add_action( 'after_setup_theme', 'mytheme_setup' );

I also did as you suggested and went back to the Menus panel and assigned theme locations. Same result: things work where they did before, and 404.php is still broken.

This is the code calling the menu from my header.php file:

<?php wp_nav_menu( array('theme_location' => 'main-navigation', 'menu' => 'Main Navigation','menu_id'=> 'headernav','menu_class'=>'navigate')); ?>

And this is the code from my 404.php file:

get_header(); ?>

    <div id="pagecontent" class="narrowcolumn" role="main">

            <article id="post-0" class="post error404 not-found">
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Oops, we couldn&rsquo;t find what you requested.', 'twentyeleven' ); ?></h1>

                <div class="entry-content">
                    <p><?php _e( 'It seems we can&rsquo;t find what you&rsquo;re looking for. Perhaps searching, or one of the links below, can help.', 'twentyeleven' ); ?></p>

                    <?php get_search_form(); ?>

                    <?php the_widget( 'WP_Widget_Recent_Posts', array( 'number' => 10 ), array( 'widget_id' => '404' ) ); ?>

                    <div class="widget">
                        <h2 class="widgettitle"><?php _e( 'Most Used Categories', 'twentyeleven' ); ?></h2>
                        <?php wp_list_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'show_count' => 1, 'title_li' => '', 'number' => 10 ) ); ?>


<?php get_footer(); ?>
share|improve this question

I'm not sure that this would be causing your problem, but one way you're definitely Doing It Wrong is referencing menu instead of theme_location in your call to wp_nav_menu().

Let's assumed you've registered your menu as "main-navigation" in functions.php, like such:

register_nav_menus( array(
    'main-navigation' => 'Main Navigation',
    'secondary-navigation' => 'Secondary Navigation'
) );

...then your wp_nav_menu() should reference this registered theme_location:

wp_nav_menu( array(
    'theme_location' => 'main-navigation',
    'menu_id'=> 'headernav',
) );

There is no inherent reason that an error 404 template page should output the nav menu any differently than any other template. If the above doesn't fix the problem, then we'll need to see more of your 404.php markup, to diagnose the problem.


Okay, I tried registering it and it had an effect: now the menu just doesn't register.

Can you update your answer, and post your register_nav_menus() code?

Note: ensure that this function call is hooked into after_setup_theme; it normally goes in a theme_setup() function, hooked into after_setup_theme, like such:

function mytheme_setup() {

    // Register Nav Menu Locations
    register_nav_menus( array(
        'main-navigation' => 'Main Navigation',
        'secondary-navigation' => 'Secondary Navigation'
    ) );

    // Other Theme-setup functions may go here
add_action( 'after_setup_theme', 'mytheme_setup' );

So, post that code in your answer.

Also, once you've registered your Theme Locations, you need to go to Dashboard -> Appearance -> Menus, and ensure that you have applied your custom menu to the appropriate Theme Location.


This is the code calling the menu from my header.php file:

<?php wp_nav_menu( array('theme_location' => 'main-navigation', 'menu' => 'Main Navigation','menu_id'=> 'headernav','menu_class'=>'navigate')); ?>

You are still passing menu and menu_id parameters to wp_nav_menu().

Why are you doing that? As I said above, that is Doing It Wrong. You need to pass only the theme_location parameter to wp_nav_menu(). WordPress then applies whatever menu is assigned via Dashboard -> Appearance -> Menus.

And this is the code from my 404.php file:

I'm not sure if it's related, but your HTML markup is malformed. You have an opening <article> tag, and no corresponding, closing </article> tag.

share|improve this answer
Thanks for your fast response! I'm not sure I understand. Why do I have to register a menu in functions.php? I built it using the Menu builder under "Appearance." – mcleodm3 Oct 27 '11 at 15:10
"Why do I have to register a menu in functions.php?" Because that's the right way to do it. You're not registering a menu in functions.php, but rather a Theme location to output a menu. – Chip Bennett Oct 27 '11 at 15:11
Okay, I tried registering it and it had an effect: now the menu just doesn't register. You can see it in action correctly here: elireview.com/how-eli-works/step-1 and incorrectly here: elireview.com/how-eli-works/step-1/blah The wp_nav_menu function is being called in header.php, which is the same from both files, which makes this extra baffling. – mcleodm3 Oct 27 '11 at 15:17
See updated answer. If things still aren't working, then we're going to need to see more code, in order to help. – Chip Bennett Oct 27 '11 at 15:22
See second update to answer. Why are you still passing menu and menu_id to wp_nav_menu()? – Chip Bennett Oct 27 '11 at 17:09
up vote 0 down vote accepted

This isn't an answer necessarily, but after some more research I found these threads:



There is some conflict or bug that causes custom menus to not render correctly on 404 pages. Changing permalinks to not use any numbers (for example, /%category%/%postname%/ ) causes the menus to render correctly.

Hopefully something they'll fix in an upcoming release :/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.