I am generating a menu in WordPress using wp_nav_menu() function and I want to add both text and variable into the 'menu_class' property.
Now this is how I do it:
`'menu_class' => 'text' . $variable,`
However no class is shown when I use this method (no error/warnings as well).
I want to know how to add the text "text" and the variable "$variable" into 'menu_class' property?
Thanks
here's the documentation for wp_nav_menu() . It says for menu_class...
the class that is applied to the ul element which encloses the menu items. Multiple classes can be separated with spaces. Formerly known as $wrap_class
so try adding a space?
'menu_class' => 'text' . ' ' . $variable,
or just
'menu_class' => 'text ' . $variable,
this is apparenlty a good tutorial: IMPROVE YOUR WORDPRESS NAVIGATION MENU OUTPUT
This SO post deals with code that deals with two menu classes: php code optimization for wordpress nav menu . Are you sure that your variable has a value? I work with PHP all the time and that's definitely how you do string concatenation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.