What you’re getting is an array so you need to implode()
them – the Walker_Nav_Menu has something like this:
$class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );
So you can modify your foreach to implode them in a similar fashion
$class = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $menu_item->classes ), $menu_item) ) );
We still want to make sure that the nav_menu_css_class
gets applied in case modifications has been made form that hook.
Related Posts:
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How can I add a class to a single menu item?
- Using a variable in is_page(array())
- Multiple WordPress Menus that will only display all pages
- get_the_tags() not iterating through for/while loop, but will with foreach
- Redirect to another page using contact form 7? [closed]
- Show About and Contact Us page when they’re clicked in the top menu.
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- wp_nav_menu not working correctly in my underscores theme
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- How to modify mobile nav menu text in theme
- Output only links using wp_nav_menu()
- How to add aria role and schema markup to custom walker container
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why in this WordPress theme I can’t see the Main Menu?
- How to make sure relative URL works when site is not on root domain?
- How to tell if a user has gone in and created a menu
- Remove the Tag from wp_nav_menu
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- How to replace hard-coded list of custom taxonomy terms based on custom field query [closed]
- What is considered good practice for registering menu locations?
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Add child pages of parent to navbar PHP
- How can I create a list of page titles from custom meta values?
- Load a page into a div with Ajax
- Recent posts with featured image or fallback image with permalink
- Call global variable array() in woocommerce child/template
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- Storing Array from returned database query and using the array in a new query
- Change list item content in menu navigation to add a child element with specific class
- Theme Options Page – User Updates Logo
- Converting HTML Template to WordPress Theme
- How to use my style.css file outside of wordpress subdomain?
- How to show part of the_content?
- Wp-login appears White Screen, Error: Cannot modify header information
- Menu Limitations
- How to remove the cufon script from Dzonia Lite theme [closed]
- get a simple array of all of the term names that exist in all taxonomies
- How can I Add a variable PHP in the Menu Nav
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- Hide categories that are not used in the post type
- Populate dropdown with Child Pages based on Parent Page chosen
- Adding an Avatar to the Top Nav Bar
- How do I add custom bulk actions to multiple custom post types?
- Add_action not working in required file of functions.php
- How to use $query->set with post__in?
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- what is the best practice to add new field to an api route
- Grab posts by multiple categories
- Can’t access variable outside for loop
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- add custom link to wordpress media gallery modal
- Reprinting tags with all attributes
- Need Help Fixing My Iframes [closed]
- Remove metabox from WordPress menu editor page?
- Avoid parallax images hardcoding
- Improve page speed loading using CDN and async or defer attribute
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- How to add an arrow to menu items has submenus
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- foreach loop still echoes array
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- post created but no permalink
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Exclude posts based on meta value
- Populate editor with some content of a page with a page template
- Title Case WordPress Menu Items
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- Menu jumping when calling it via PHP
- Displaying recent posts on static page with template-part via shortcode
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- How to edit widget code to add unique class name to each div?
- Checking array against author id in loop
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Skt full width basic slideshow problem
- Trying to store submenu items to render out after main menu
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How to change menu order item
- How to disable controls in theme customizer?
- How do I link a button I created in theme customizer to a function?
- Trying to retrieve post meta
- can i fetch a custom metabox data in another page or post type?
- Custom Menus: dynamic highlighting problem with custom home link
- Is there a way to conditionally check whether a WordPress post title is empty?
- get_the_title() gets printed out twice
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- get_template_part for specific page