wp_nav_menu not parsing properly..?
-
Hello,
Hoping for some advice from the awesome WP community.
On my local server, I have WP 6.02 installed, and everything works great. On my online “staging” site, I also have 6.02 installed, but something ain’t working right with wp_nav_menu(). Here is the relevant code in my header.php file:
<div id='nav_menu-container' class='nav_menu-container'> <?php if ( has_nav_menu( 'main' )) { wp_nav_menu( [ 'menu' => 'Main Menu', 'theme_location' => 'top', 'container' => 'nav', 'container_id' => 'main_menu-container', 'menu_id' => 'main_menu', 'menu_class' => 'main_menu', ]); } americancyanide_login_menu(); ?> </div>
I have assigned a class to the nav container of main_menu-container. The generated UL is then supposed to get the ‘main_menu’ id and class. Again, on my local server, works perfect, but on my online version, the main_menu class is put on the nav container, thus rendering the CSS rules useless.
Have I forgotten to do something?
- This topic was modified 2 years, 3 months ago by wileycoyote78. Reason: Removed the tabs from the code sample so scrolling to view is not necessary
The page I need help with: [log in to see the link]
-
Hi @wileycoyote78,
I investigated the issue locally, and I was able to reproduce it.
It happens if the theme location menu isn’t selected through the WordPress dashboard Menu page. In our case, the
top
menu (defined in the wp_nav_menu function arguments:'theme_location' => 'top',
).Here are some helpful screenshots:
- No location selected (incorrect class placement): https://snipboard.io/1G2hz5.jpg
- Location selected (correct class placement): https://snipboard.io/WlZ2pt.jpg
Please set the top location to the main menu as shown on https://snipboard.io/NeyiqV.jpg (the bottom display location checkbox) and let us know if it works.
- This reply was modified 2 years, 3 months ago by aatanasov.
Never mind. In looking into the issue some more I saw some folks stating they had a similar problem when their WP was upgraded to 6.02 and said they had to delete the menu and build it again.
I didn’t think this would work because I did not create the menu that long ago.
In any case, I tried it, and everything is peachy keen.
Hi @aatanasov
I deleted the menu and rebuilt it in the admin panel, and it seems to have corrected the problem. The interesting thing is, the menu was working before. I updated some style rules locally and uploaded the changes to my staging site tonight and that is when it broke. I did not change anything in the menu save the class names.
I do appreciate you looking into it. I will keep the
theme_location
tip in mind should I run into the issue again.
- The topic ‘wp_nav_menu not parsing properly..?’ is closed to new replies.