$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Custom menu is rendered in all menus|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Custom menu is rendered in all menus

matteradmin9PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far