Support » Themes and Templates » register_nav_menu

  • Resolved christian_gnoth

    (@christian_gnoth)


    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.

Viewing 15 replies - 1 through 15 (of 29 total)
  • 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

    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.

    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

    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

    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

    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 .

    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

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

    simply it is not working.

    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

    i did, still not working

    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.

    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.

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

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

    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.

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘register_nav_menu’ is closed to new replies.