Support » Fixing WordPress » register_nav_menu not actually registering menus?

  • Resolved jfeaver

    (@jfeaver)


    I’m having trouble registering custom menus and getting them to work correctly. Instead of using the specified menu with wp_nav_menu(array(…)); the menu with the lowest id is used by default.

    Here’s the pastebin info:
    http://pastebin.com/7xy9G0Sj

Viewing 14 replies - 1 through 14 (of 14 total)
  • Can you replicate the problem using the Twenty Eleven theme with all plugins deactivated?

    yep, the same thing happens there too.

    Okay, so I’m getting into the backend, doing some debugging and still not figuring this out. I’m wondering if maybe it is because I’m on a local LAMPP server and maybe something’s not getting stored in the local database correctly?? That would still surprise me a little bit though because the Admin GUI shows that my menus are being saved and that my theme allows for the new custom menu options.

    From within wp_nav_menu, a call to wp_get_nav_menu_object returns false which means that get_term and get_term_by are also returning false. The nav menu items exist on my database when I look on the wp_posts table in my phpmyadmin. I’m confused when I look at the menu items though. They don’t seem to have any identifying information on them(like page ids or links) and only say ‘nav_menu_item’ under the post_type heading and have a number under post_name (different from the page id of the link).

    Where can I find the name of the custom menus that I’m creating in the database? Do I have a problem setting up the custom menus in functions.php or am I calling them incorrectly in header.php? I’m so confused. Thanks for help!

    Okay, I was completely disappointed about getting no help on this. I thought you’d be better than this WP forums. WP should make this place more like StackOverflow 🙂

    I finally figured out the problem. I need to use ‘theme-location’ rather than ‘menu’ as my key in the wp_nav_menu argument. Ugg…

    Nope, nm that didn’t work either… ugg…

    But, I did think that it was working because it is working with menus in the page templates. For whatever reason, if I put this functionality into header.php then it won’t work but works fine in a page template.

    Have you added custom menu support to your theme?

    Maybe?? I started from the Foundation theme. It might have added them already.

    How do I add custom menu support?

    I’d suggest that you review Navigation_Menus.

    Have you looked at my Pastebin?? That’s all in there. I know how to register and add menus with the correct php functions. I was wondering if there was something like:

    wp_theme_uses_custom_menus(‘init’)

    Like I said, the feature is working in my page templates but not in my header.php. Any thoughts?

    Have you looked at my Pastebin??

    Yes. And if that’s all there is in your functions.php file, then you have not added custom menu support to the theme. Please see the page at the link I gave above.

    Okay, I’m sorry. I think that I did do everything on the link that you gave. I did add a function:

    function bt_register_custom_menus() {
    register_nav_menu(‘header_left’, __(‘Header Left’));
    register_nav_menu(‘header_right’, __(‘Header Right’));
    register_nav_menu(‘home_left’, __(‘Homepage Left’));
    register_nav_menu(‘home_right’, __(‘Homepage Right’));
    }

    I also added an add_action:

    add_action(‘init’, ‘bt_register_custom_menus’);

    From what I understand of the information in the link, that is all I need. Then I can go ahead and add menus using wp_nav_menu and specify menus to use in Appearance->menus. Is this correct? What else do I need to add to my functions.php?

    Go and read the page I linked to above!

    I have read the page that you linked. I’ve read it twice now and glanced over it a few more times. I’m really trying and I’m sorry that I’m frustrating you.

    The only extra pieces of information that I read about is the optional register_nav_menus for more than one menu, which I’ve now implemented, and the option to give your menu a class in wp_nav_menu.

    I’m really trying and still not knowing what to try next. If you know the answer, could you please tell me explicitly?

    If anyone else is having this same issue, I’m also starting a conversation at StackOverflow. Maybe they will know what’s up with this weird header.php funkery.

    Yep, they were able to help me. I just put a hyphen instead of an underscore. So… I did read the page and I did have all the info I needed.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘register_nav_menu not actually registering menus?’ is closed to new replies.