0

I have registered the following menus in my functions.php

// register menus
function register_menus() {
    register_nav_menus(
        array(
            'footer-01' => 'Footer 01',
            'footer-02' => 'Footer 02',
            'footer-04' => 'Footer 04'
        )
    );
}
add_action('init', 'register_menus');

I've set them up with their each own set of links.

Now I've put the following into my theme files to show them on the pages:

<?php wp_nav_menu( 'footer-01' ); ?>
<?php wp_nav_menu( 'footer-02' ); ?>
<?php wp_nav_menu( 'footer-04' ); ?>

But it seems that each menu outputs the same set of links, they all show the links that have been added to the footer-04 menu

How do I get menus 01 and 02 to show their own links?

1 Answer 1

1

I have registered the following menus in my functions.php

Note that register_nav_menus() which uses register_nav_menu() (note the singular "menu") does not register or create a navigation menu; it only registers navigation menu locations which you can assign one or more (navigation) menus to, and for displaying the menus assigned to a specific location, you can use wp_nav_menu() just as you've already tried.

How do I get menus 01 and 02 to show their own links?

The problem in your wp_nav_menu() call is because you're not specifying the proper navigation menu location which is identified by the theme_location parameter like so:

<?php wp_nav_menu( 'theme_location=footer-01' ); ?>
<?php wp_nav_menu( 'theme_location=footer-02' ); ?>
<?php wp_nav_menu( 'theme_location=footer-04' ); ?>

More details based on the wp_nav_menu()'s reference:

Usage

wp_nav_menu( $args );

Given a theme_location parameter, the function displays the menu assigned to that location. If no such location exists or no menu is assigned to it, the parameter fallback_cb will determine what is displayed.

If not given a theme_location parameter, the function displays

  • the menu matching the ID, slug, or name given by the menu parameter; e.g. wp_nav_menu( 'menu=123' ) or wp_nav_menu( [ 'menu' => 'My Menu' ] )

  • otherwise, the first non-empty menu;

  • otherwise (or if the menu given by menu is empty), output of the function given by the fallback_cb parameter (wp_page_menu(), by default);

  • otherwise, nothing.

(Note: I slightly modified the above quote.)

So be sure to check the reference/docs and supply the proper function arguments. And remember that the above $args can be an array like array( 'key' => 'value' ) (or [ 'key' => 'value' ]) or a query string like key=value&key2=value+2. Both will work in most cases, but when the value contains a space or the value is complex (e.g. it contains HTML tags), then you should use the array format. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.