Menu classes not coming in html with menu_class=’nav ‘ | Solved | wp_nav_menu WordPress

No Comments

wp_nav_menu – This page describes how to add menu’s to our wordpress site / theme. But people are getting an error ul class doesn’t work perfectly sometimes. I faced this error and on the same second googled it but couldn’t find a solution to it. Saw many people looking for the same thing, so I decided to write on it for few minutes.

The problem as seen on this wordpress forum page

<?php wp_nav_menu(array('menu_class' => 'menuclass', 'container_class' => 'containerclass')); ?>

I’d expect it to apply ‘menuclass’ to the ul, and ‘containerclass’ to the container div… But it doesn’t. It prints like this:

<li><a title="Home" href="#">Page 1</a></li> <li><a href="#">Page 2</a> 
//This person on wordpress forum also had the same problem


<?php wp_nav_menu(array('menu_class' => 'menuclass', 'container_class' => 'containerclass',
'fallback_cb'=> 'false' )); ?>


'fallback_cb'=> 'false' to wp_nav_array to solve the ul class error.

Whats fallback

(string) (optional) If the menu doesn’t exist, the fallback function to use. Set to false for no fallback. Note: Passes $args to the custom function.
Default: wp_page_menu

No strict reason found why adding this corrects the things, but somehow this is the only solution i found till date. The reason of writing this post is to know from you people, is there any other better solution to this.

Best Regards
Twitter – anibabbar

A website developer, loves #wordpress #drupal #php. Love posting about wordpress, php, bootstrap and SEO. Also provide online/offline training on wordpress, drupal, php and SEO. I am available on Twitter @ anibabbar , Skype @anibabbar , gmail @anibabbar !! facebook

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

Fields marked with an * are required
November 2019
« Sep    

More from our blog

See all posts
No Comments