WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] register_nav_menu (30 posts)

  1. christian_gnoth
    Member
    Posted 3 years ago #

    in my theme i have added two menus with

    if ( function_exists( 'register_nav_menus' ) )
      {
        register_nav_menus(
                array(
                    'header-menu' => __( 'Header Menu' ),
                    'extra-menu' => __( 'Extra Menu' )
                     )
        );
      }

    but the two menu locations are not displayed in the wp admin area under Appearance -> Menus.

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    Not sure if this is relevent but as you are using the two underscores, do they have to be added to the language file?

    Nothing jumps out of the code, it looks fine, don't think it needs a closing comma

    'Extra Menu' ),

    Some arrays have some don't from what I have seen.

    Failing that you could just try:

    if ( function_exists( 'register_nav_menus' ) )
      {
        register_nav_menus(
                array(
                    'header-menu' => 'Header Menu',
                    'extra-menu' => 'Extra Menu',
                     )
        );
      }

    David

  3. christian_gnoth
    Member
    Posted 3 years ago #

    thanks for the hint, i changed the code, but still it is not working and under the menu page these two locations are not displayed.

  4. Digital Raindrops
    Member
    Posted 3 years ago #

    I just had a thought, if the "Theme Location" dialog box is not displayed try this:

    Admin > Appearance > Menus

    Then top right click on [Screen Options], drop down to 'Show on Screen'
    and check that the check box for the menu locations is 'checked' (ticked)

    You may have hidden it for another theme?

    David

  5. christian_gnoth
    Member
    Posted 3 years ago #

    I have the following options available:

    Show on screen
    Custom Links Posts Pages Categories Post Tags

    Show advanced menu properties
    Link Target CSS Classes Link Relationship (XFN) Description

  6. Digital Raindrops
    Member
    Posted 3 years ago #

    It is not happy about something, what theme are you using, and you are sure you have WordPress 'version 3'?

    Try this in your functions.php with your themes namespace like 'twentyten'.

    if ( function_exists('register_nav_menus')) :
    	register_nav_menus( array(
    		'header' => __( 'Header Menu', 'twentyten' ),
    		'extra' => __( 'Extra Menu', 'twentyten' ),
    	) );
    else:
    	echo 'Function Not Found!';
    endif;

    If if fails you should see a text line.

    HTH

    David

  7. govpatel
    Member
    Posted 3 years ago #

    Try this

    if (function_exists('wp_nav_menu')) {
    	add_action( 'init', 'register_my_menus' );
    	function register_my_menus() {
    	register_nav_menus(
    	array(
    	'page-menu' => __( 'Page Menu' ),
                      'category-menu' => __( 'Category Menu' ),
    	)
    	);
    	}
    	}

    You can change Page Menu and Category Menu what ever you want .

  8. Digital Raindrops
    Member
    Posted 3 years ago #

    Christian,
    Maybe put your code into the WordPress Pastebin and link in a reply.

    You should not need to wrap the code in another function, you did add the code in the functions.php file and it is not a child theme?

    David

  9. christian_gnoth
    Member
    Posted 3 years ago #

    the register_nav_menus function is in my theme init function. there is no error message.

    simply it is not working.

  10. Digital Raindrops
    Member
    Posted 3 years ago #

    Christian,
    Just put it in the functions.php file not inside another function, I have created loads of 'WordPress 3' themes for tutorials.

    All I do is put it in the functions.php theme or after_setup_theme function, and they works.

    In a non-child theme or a theme I am upgrading, I just add in the file not inside any function!

    register_nav_menus( array(
    	'primary' => __( 'Below Header', 'atmosphere' ),
    	'secondary' => __( 'Above Header', 'atmosphere' ),
    ) );

    In a twenty ten based child themes functions.php, adding two more menus, inside 'after_setup_theme'

    add_action( 'after_setup_theme', 'child_theme_setup' );
    
    function child_theme_setup() {
       /* This theme uses wp_nav_menu() in three locations. */
    	register_nav_menus( array(
    		'top' => __( 'Top Navigation', 'twentyten' ),
                      'footer' => __( 'Footer Navigation', 'twentyten' ),
    	) );
    }

    These both work.

    HTH

    David

  11. christian_gnoth
    Member
    Posted 3 years ago #

    i did, still not working

  12. govpatel
    Member
    Posted 3 years ago #

    once you add the function you need to add a code to header.php to get the menu to work.

    <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

    instead of the menu code or code it.

  13. govpatel
    Member
    Posted 3 years ago #

    once you add the function you need to add a code to header.php to get the menu to work.

    <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>

    change primary to what ever you named the menu in function.php

    instead of the menu code or code it.

  14. christian_gnoth
    Member
    Posted 3 years ago #

    the problem is, that the menu is not shown in the wp admin menu page

  15. govpatel
    Member
    Posted 3 years ago #

    what theme are you using if its from repository may be I install and see where problem is .

  16. christian_gnoth
    Member
    Posted 3 years ago #

    I have this problem with different themes - even with the default twentyten theme i have this problem.
    so it is not the theme, but something in the wordpress installation.

  17. govpatel
    Member
    Posted 3 years ago #

    There may be some other problem if you have same problem with twenty ten theme as it is already set up for custom menu.

    Have you tried to upload all wordpess files and folder except wp-content folder and wp-config.php file as wp-content will have all your contents and wp-config.php has your database info as well as settings.

    Then try if you still have problem with twenty ten theme.

  18. woeye
    Member
    Posted 3 years ago #

    Greetings everyone!

    I'm currently facing the very same problem. It's a fresh locale installation (PHP 5.3.3) and both my own theme and twentyten do not work. Do not work means that my custom menu won't show up in WP Admin.

    Here's my theme code:

    function register_custom_menus() {
    	register_nav_menus(array(
    		'primary' => 'Primary Navigation',
    	));
    }

    add_action('after_setup_theme', 'register_custom_menus');

  19. christian_gnoth
    Member
    Posted 3 years ago #

    I have at a different webserver with new installation of wp 3.0 the same problem !!!

  20. govpatel
    Member
    Posted 3 years ago #

    Did you try deactivate your plugins as its strange that custom menu do not work on default twenty ten theme. post your url so that I can check may something on computer is blocking it.

    Click on my website and see if you get drop down.

  21. Digital Raindrops
    Member
    Posted 3 years ago #

    Christian,
    As you have a local install activate 'Twenty Ten' check in the database wp_options table to see if the menu locations were created and registered.
    look for the record 'mods_Twenty Ten' and in the detail

    a:2:{s:12:"header_image";s:80:"http://localhost/wordpress/wp-content/themes/twentyten/images/headers/sunset.jpg";
    s:18:"nav_menu_locations";a:1:{s:7:"primary";i:3;}}

    If not see if the register function can be found, I just add a message for debugging in one of the files:

    <?php if ( function_exists( 'register_nav_menus' ) ) : ?>
        <h2>Function found register_nav_menus</h2>
    <?php else : ?>
        <h2>Function not found register_nav_menus</h2>
    <?php endif; ?>

    I have the latest WordPress with PHP 5.3.0 and all is well, what version does your ISP hosting plan use?

    Did you do a manual install of WordPress or a one click wizard?
    Are you using the super administrator role?

    I know these are obvious but that is often where we end up, something like permissions (roles and capabilities) not setting correctly!

    HTH

    David

  22. woeye
    Member
    Posted 3 years ago #

    adeptris,

    I've added the check-code and the function seems to exist for it says function found.
    In wp_options, however, there's no such thing as mods_Twenty ten or ..."nav_menu_locations"?

    I am using mysql 5.1.48 and PHP 5.3.3 from MacPorts. It's a fresh and clean local installation. No plugins in the browser.

    Thanks,
    Lars

  23. Digital Raindrops
    Member
    Posted 3 years ago #

    Ok,
    I just tested it, and here is what is happening!

    The theme locations will not show in the Appearance > Menus until you add a menu.

    Enter a 'Menu Name' in the main area, add menu items and save, then the theme locations will Appear!

    David! (Duh! something so obvious lol)

  24. woeye
    Member
    Posted 3 years ago #

    In other words, theme menus will not show up before you have added at least one sample menu from WP admin?

  25. Digital Raindrops
    Member
    Posted 3 years ago #

    In other words, theme menus will not show up before you have added at least one sample menu from WP admin?

    That's the one!

    Christian, if this fixes it, mark as resolved please!

    David

  26. woeye
    Member
    Posted 3 years ago #

    Hm, but I wonder why I have to add some menu myself when the theme is supposed to provide the menus it knows? As an end user I wouldn't expect that I have to add one random menu myself in order to unlock the theme provided menus.

  27. Digital Raindrops
    Member
    Posted 3 years ago #

    The themes custom menu will default to a listing of wp_pages, so it is providing the menu that many would expect, when changing a theme.

    Many bloggers however will just activate a theme and post away, never addimg a plugin or touching any other settings.

    When designing themes you have to think about who might use or download the theme, and how aware or novice they might be, as many are put off by anything that does not "work right out the box"

    Note:
    If you want an optional or second menu, or do not want a menu/menu's showing the pages, use the argument fallback_cb and pass in no value '', then the menu will not show if it is not assigned to a theme_location.

    <?php wp_nav_menu( array( 'theme_location' => 'secondary', 'fallback_cb' => '' ) ); ?>

    David

  28. woeye
    Member
    Posted 3 years ago #

    Ok, I see. Makes perfect sense. Thank you, David!

  29. christian_gnoth
    Member
    Posted 3 years ago #

    thank you for this hint, I have added a test menu and then theme locations appeared.

  30. thamiziniyan
    Member
    Posted 3 years ago #

    Included the second menu successfully by editing heder.php and functions.php. i got the two memu locations, and my site display two menus. but the thing is the second menu didn't follow the css style. I think i have to edit style.css. Can anyone help me?

    i'm customizing twenty ten theme to my wish.

    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.