Custom menu is rendered in all menus

admin2025-06-05  1

I am currently working on my own theme. In this theme I want two menus topmenu and bottommenu.

In the functions.php file I have the following code:

// This adds the support to add a thumbnail and custom menus
function thumbnail_menu_support() {
    add_theme_support( 'post-thumbnails' );
    register_nav_menus(
        array(
            'topmenu' => __( 'Top menu' ),
            'bottommenu' => __( 'Bottom menu' )
        )
    );
}
add_action( 'init', 'thumbnail_menu_support' );

In my header.php and in the footer.php I have the following code:

<?php wp_nav_menu( array(
    'menu'              => 'Top menu',
    'menu_id'           => 'topmenu',
    'container'         => false,
    'fallback_cb'       => false,
    'theme-location'    => 'topmenu'
) ); ?>

and

wp_nav_menu( array(
    'menu'              => 'Bottom menu',
    'menu_id'           => 'bottommenu',
    'container'         => false,
    'fallback_cb'       => false,
    'theme-location'    => 'bottommenu'
) );

Now, when I make a menu in the backend of Wordpress, and specify that it should only be in the top menu, it will be rendered in both menus.

See this:

I am currently working on my own theme. In this theme I want two menus topmenu and bottommenu.

In the functions.php file I have the following code:

// This adds the support to add a thumbnail and custom menus
function thumbnail_menu_support() {
    add_theme_support( 'post-thumbnails' );
    register_nav_menus(
        array(
            'topmenu' => __( 'Top menu' ),
            'bottommenu' => __( 'Bottom menu' )
        )
    );
}
add_action( 'init', 'thumbnail_menu_support' );

In my header.php and in the footer.php I have the following code:

<?php wp_nav_menu( array(
    'menu'              => 'Top menu',
    'menu_id'           => 'topmenu',
    'container'         => false,
    'fallback_cb'       => false,
    'theme-location'    => 'topmenu'
) ); ?>

and

wp_nav_menu( array(
    'menu'              => 'Bottom menu',
    'menu_id'           => 'bottommenu',
    'container'         => false,
    'fallback_cb'       => false,
    'theme-location'    => 'bottommenu'
) );

Now, when I make a menu in the backend of Wordpress, and specify that it should only be in the top menu, it will be rendered in both menus.

See this:

Share Improve this question asked Dec 23, 2018 at 18:10 Christof KälinChristof Kälin 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I actually found the answer on stackexchange as well: https://wordpress.stackexchange/a/184149/132736

I need to replace the 'theme-location' by 'theme_location'. I simply misread the function reference on the WordPress codex.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749068725a316081.html

最新回复(0)