customization – Custom menu not showing even though it shows as being registered?

Question

I’m running into a really weird problem.

Some quick background: I cloned this workflow from one I’ve been using before but just updated everything including node packages and the gulp functions and workflow. This worked perfectly fine before and now it’s suddenly giving errors and not working as expected.

So I’m trying to create custom menus and have them registered like I normally do:

register_nav_menus([
            'primary' => 'Primary Menu',
            'secondary' => 'Footer Menu',
            'tertiary' => 'Legal Menu'
        ]);

I noticed it doesn’t display at all but still shows up in the admin dashboard to add/remove items. So I did some testing and this is what I got:

<?php
                        $menus = get_registered_nav_menus();
 
                        foreach ( $menus as $location => $description ) {
                         
                            echo $location . ': ' . $description . '<br />';
                        }

                        echo has_nav_menu('primary')?'true<br />':'false<br />';
                        $registered_nav_menus = get_registered_nav_menus();
                        echo isset( $registered_nav_menus[ 'primary' ])?'true<br />':'false<br />';
                        
                        $locations    = get_nav_menu_locations();
                        var_dump($locations) ;

                        $locations = get_theme_mod( 'nav_menu_locations' );
                        print_r($locations);    

                        wp_nav_menu( array( 
                            'menu' => 'primary', 
                            'theme_location' => 'primary',
                        )); 
                        ?>

And this code give me this output:

primary: Primary Menu
secondary: Footer Menu
tertiary: Legal Menu

false
true

array(0) { } 
Array ( )

// These are not the correct menu items, it should only be showing the first 3. This is showing all pages on the website
Home
About
Contact
Privacy Policy

Basically, some functions show that it is registered and show the registered menus, while others show it isn’t. I normally don’t ask questions here because it’s usually an error on my end so I eventually manage to find the problem, but in this case I can’t think of any other reason this could happen unless there’s a bug in the latest WordPress version.

If anyone could provide some insight on this that’d be amazing as I’m completely stumped!

WordPress version: 5.9
PHP version: 7.4.27

0
Jan 1 year 2022-02-15T18:20:12-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse