2

I've looked everywhere, but i can't find a solution.

My secondary menu isn't adding any current classes to the

  • tags when it's rendered.

    I have added this menu in my functions.php file

    function register_menus() {
        register_nav_menus(
            array(
                'second-menu' => __( 'Second Menu' )
            )
        );
    }
    

    Then I created a menu in wordpress with the links I want to show in my Second Menu. After that I've added the menu with the function wp_nav_menu in the .php file where I want the menu to show:

    <?php wp_nav_menu( array( 'theme_location' => 'second-menu' ) ); ?>
    

    So far everything works. The menu is showing with the links I want it to show. All the links are working. My problem is, that the 'current' classes which WP normally adds to the menus aren't added to this menu. I've expected the classes current-menu-item or current-page-item to the

  • tag, but these aren't there. The only classes which WP adds to the
  • tag are:

    • menu-item
    • menu-item-type-post_type
    • menu-item-object-page
    • menu-item-[number]

    Thanks for the help, Angelo

    2 Answers 2

    5

    You need to assign the menu to the particular theme option from the admin end,

    Orelse use this code,

    wp_nav_menu( array( 'menu' => 'second-menu' ) );
    

    Instead of,

    wp_nav_menu( array( 'theme_location' => 'second-menu' ) );
    

    This will work.

    3
    • When I do this, the main-menu shows instead of the menu I want to show (second-menu). From the admin end, you mean url.com/wp-admin right? I created a menu there which includes the link I want to show.
      – anche
      Apr 22, 2014 at 12:44
    • @AngeloA.. Have you assigned the newly created menu to the "Second Menu" when you create the menu. Only then it will be showing up when you use the theme_location in it. Apr 22, 2014 at 13:34
    • I've edited my post
      – anche
      Apr 23, 2014 at 12:14
    1

    These don't match:

    register_nav_menus(
        array(
            'second-menu' => __( 'Second Menu' )
        )
    );
    

    and

    wp_nav_menu( array( 'theme_location' => 'producten-menu' ) )
    

    Your 'theme_location' must match the slug passed to the register_nav_menus() array:

    register_nav_menus( array( $slug => $title ) );
    

    gets called as:

    wp_nav_menu( array( 'theme_location' => $slug ) );
    

    So try:

    wp_nav_menu( array( 'theme_location' => 'second-menu' ) );
    
    4
    • Ah, thanks. I've changed it, but it's still not working :(
      – anche
      Apr 21, 2014 at 9:08
    • Please elaborate on "it's still not working". What are you expecting to happen, and what's actually happening? Apr 21, 2014 at 11:40
    • The menu is showing, but the problem is that no current-classes are added to the menu. So I can't add use CSS to show the active (current) menu-item.
      – anche
      Apr 22, 2014 at 12:43
    • Please edit your question to include what you've tried, what you expected to happen, and what actually happened (including the actual classes output, where you expect a "current" class to be output). Also, did you assign a custom nav menu to the Theme Location? Apr 22, 2014 at 12:54

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.