Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

  • share|improve this question

    2 Answers 2

    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' ) );
    
    share|improve this answer
        
    Ah, thanks. I've changed it, but it's still not working :( –  Angelo A Apr 21 at 9:08
        
    Please elaborate on "it's still not working". What are you expecting to happen, and what's actually happening? –  Chip Bennett Apr 21 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. –  Angelo A Apr 22 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? –  Chip Bennett Apr 22 at 12:54
        
    I've edited my post. Thanks for the help so far. –  Angelo A Apr 23 at 12:14

    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.

    share|improve this answer
        
    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. –  Angelo A Apr 22 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. –  Harish Chinju Apr 22 at 13:34
        
    I've edited my post –  Angelo A Apr 23 at 12:14

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

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