WordPress.org

Support

Support » How-To and Troubleshooting » Problem with register_nav_menus (in functions.php) and wp_nav_menu (header.php)

Problem with register_nav_menus (in functions.php) and wp_nav_menu (header.php)

  • I have a problem showing the menus in my WordPress theme Mantra, the problem is that when I write new menus in my functions.php(like this):

    <?php
    
    function registrar_mis_menus() {
    register_nav_menus(
        array(
          '2' => 'Segundo',
          '3' => 'Tercero',
          '4' => 'Cuarto',
          '5' => 'Quinto',
          '6' => 'Sexto',
          '7' => 'Septimo'
        )
      );
    }
    add_action( 'init', 'registrar_mis_menus' );
    
    ?>

    And in the header.php:

    <?php wp_nav_menu( array( '2' => 'Segundo', 'container_class' => 'menu' )); ?>
    <?php wp_nav_menu( array( '3' => 'Tercero', 'container_class' => 'menu' )); ?>
    <?php wp_nav_menu( array( '4' => 'Cuarto', 'container_class' => 'menu' )); ?>
    <?php wp_nav_menu( array( '5' => 'Quinto', 'container_class' => 'menu' )); ?>
    <?php wp_nav_menu( array( '6' => 'Sexto', 'container_class' => 'menu' )); ?>
    <?php wp_nav_menu( array( '7' => 'Septimo', 'container_class' => 'menu' )); ?>

    They seem to work right in the admin Panel:

    http://img209.imageshack.us/img209/6332/capturadepantallan.png

    But when i go to any page of my site they show the same link on all the menus::

    http://img217.imageshack.us/img217/3880/menuconlosenlacesrepeti.png

    ¿How can I solve this problem?, ¿Theres a problem with my code, or with that theme?

    Help, ¡Please!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I believe that the numeric keys used in register_nav_menus() cause problems, and that wp_nav_menu() needs the ‘theme_location’ argument rather than the key of the menu assigned by register_nav_menus().

    Try coding the register_nav_menus() like this:

    register_nav_menus(
        array(
          'm2' => 'Segundo',
          'm3' => 'Tercero',
          'm4' => 'Cuarto',
          'm5' => 'Quinto',
          'm6' => 'Sexto',
          'm7' => 'Septimo'
        )
      );
    }

    and the wp_nav_menu() calls like this one:

    php wp_nav_menu( array( 'theme_location' => 'm2', 'container_class' => 'menu' )); ?>

    Why is it that you want to add a separate menu for each menu item?

    There should be only one “main menu”, and all its “items” in it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with register_nav_menus (in functions.php) and wp_nav_menu (header.php)’ is closed to new replies.