• Resolved Wabsnasm

    (@wabsnasm)


    I’m mystified.

    I’ve got a register_nav_menus call attached to the wp_loaded hook like this:

    register_nav_menus(array('footer' => 'Footer links'));

    I’ve created a nav and added links in the admin interface, then saved. Next, I’ve applied that menu to the ‘Footer links’ location, and have saved.

    Lastly, in footer.php I do this

    echo has_nav_menu('footer') ? 'true' : 'false';
    wp_nav_menu(array('theme_location' => 'footer'));

    and all that’s showing is ‘true’. The ‘theme_location’ property just doesn’t seem to be working. I can get the menu to show by doing this

    wp_nav_menu(array('menu' => 'Footer menu name'));

    but of course that’s not as good. Can anyone tell me what I’m doing wrong?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Wabsnasm

    (@wabsnasm)

    An update –

    wp_nav_menu(array('menu' => 'Footer menu name'));

    Does not get the correct menu, and changing ‘container’ and ‘container_class’ arguments make no difference.

    Thread Starter Wabsnasm

    (@wabsnasm)

    Solved

    I was hooking into pre_get_posts and modifying the query there. That was preventing the menu from being output on the pages where I was doing that.

    To resolve this, I added a &query->is_main_query conditional. So,

    add_filter('pre_get_posts', 'my_filter');
    function my_filter(&$query) {
      if ($query->is_main_query() && (is_single() || is_home())) {
        // Modify query here
      }
    }

    Once I’d added that, my wp_nav_menu started working. Solution presented here in case anyone else comes up against the same issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_nav_menu outputting nothing!’ is closed to new replies.