WordPress.org

Ready to get started?Download WordPress

Forums

Issues registering nav_menu's from functions.php (6 posts)

  1. Richard K
    Member
    Posted 1 year ago #

    Hi, I'm running on 3.4.2 and developing a theme and struggling to get nav menu's sorted.

    Basically what I want is to register an menu in WordPress, that is set by default when you go to Appearance -> Menu's. So when the theme is installed there will be e.g. "Main menu" at the top, which then can't be removed from WordPress.

    I have added add_theme_support('menus'); and:

    function registerNavMenus() {
      register_nav_menus(
        array(
          'a' => 'A',
          'b' => 'B',
        )
      );
    }
    
    add_action( 'init', 'registerNavMenus' );

    I have read about 2 dozen pages on wordpress.org (on theme development) and several blog posts on external pages, and trying a lot, but can't seem to get it right. What an I doing wrong?
    But for some reason I can't

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    which then can't be removed from WordPress.

    If you want a fixed menu then you shouldn't be adding a custom menu to this location.

  3. Richard K
    Member
    Posted 1 year ago #

    So what should I do? When I say can't be removed, I mean by an administrator user in wordpress. Like you can add a menu from the GUI, by clicking a plus, and you can then delete the added one. I want a fixed one, presumably set from the code.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Then I'd suggest using something other than wp_nav_menu() - such as wp_list_pages() or wp_page_menu().

  5. Richard K
    Member
    Posted 1 year ago #

    I'm creating a generic theme and want to use custom theme's, because there will be a main nav that will always need to be set... e.g. wp_list_pages is not what I'm looking for. Is there no way to specify a menu that is there permanently? So can I only specify a theme location that can be bound to a menu that has been made by hand?

  6. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    In effect, yes. The whole point behind wp_nav_menu() is that it will allow appropriate users to create a custom menu to be used at that location.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags