user10956303
user10956303

Reputation:

How to fix my header menu changing when new menu is created?

I want to create a submenu in a page I can access from my header menu. I created the submenu, I added a line in my "register_nav_menus". The page I want the submenu to be has the code with the theme_location corresponding to the code added to "register_nav_menus".

Now my header menu is the submenu I just created. (I updated the location in menu's admin page).

I don't really what I can do to fix that problem. I'm pretty new to WP.

Here's the code:

FUNCTIONS.PHP
// Theme Setup
function mairie_setup() {
    // Navigation resgister
    register_nav_menus(
        array(
            'header' => __('Menu principal'),
            'subnav' => __('Sous menu')
        )
    );
}
add_action('after_setup_theme', 'mairie_setup');

HEADER.PHP
...
<nav class="navbar">
    <?php
        $args = array(
        'theme_location' => 'header'
    );
    wp_nav_menu() ?>
</nav>
...
THEME FOR SUBNAV
...
<nav class="sub_navbar">
    <?php
    $args = array(
        'theme_location' => 'subnav'
    );
    wp_nav_menu() ?>
</nav>
...


I'd like my header menu to stay the header menu and not change if I create a new menu.

Upvotes: 0

Views: 39

Answers (1)

ripon
ripon

Reputation: 51

<nav class="navbar">
  <?php
    $args = array(
      'theme_location' => 'header'
    );
    wp_nav_menu($args);
  ?>
</nav>
<nav class="sub_navbar">
  <?php
    $argss = array(
      'theme_location' => 'subnav'
    );
    wp_nav_menu($argss);
  ?>
</nav>

please try this one. and read more about https://developer.wordpress.org/reference/functions/wp_nav_menu/

Upvotes: 1

Related Questions