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]
- PHP unit testing WordPress?
- List of all theme customizer control types?
- Metabox repeating fields – radio buttons not saving correctly
- How can merge two arrays values in one array and save in database
- renaming an admin menu item with decimal array index number
- Compare two meta key values against each other inside the get_posts array?
- Multiple do_shortcode($content) within one shortcode
- Replacing the NavWalker dropdown element
- How to add specific menu on a specific page or pages
- WordPress menu deletes when trying to add a hook
- Widgets not showing in my custom theme
- Can an array be used as a meta_query value?
- List of posts by day of the week
- selected menu item
- What is the fastest way to load PHP functions that are only used in one theme template?
- How do I access the media settings
- Can’t load WP function into external function
- Create shortcodes within foreach loop (using array)
- Implement toggle switch for theme options in settings API
- Show comments menu in dashboard only if the site has comment
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- Count top level menu items
- How can i upload images in an admin page?
- Wp-login appears White Screen, Error: Cannot modify header information
- Reprinting tags with all attributes
- Need Help Fixing My Iframes [closed]
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How do I link a button I created in theme customizer to a function?
- can i fetch a custom metabox data in another page or post type?
- Add item to top of menu using a filter in functions.php
- ‘Post-thumbnails’ feature does not seem to register
- How to obtain the current website URL in my theme?
- Grouping posts by a custom meta value
- Separation of presentation and code – WordPress
- Search form does not work in my website
- get_template_directory adding FTP root folders in urls
- Error while setting role
- Automatically add images to a menu
- Live to Local on MAMP, not working, outputting functions.php code
- Loop over Array and get the distinct ids
- Remove empty terms from array, sort alphabetically, update back to repeating field
- Only show first image in foreach loop
- Filter by field with array value in ACF on WP REST API
- How to Update an old theme for the latest wordpress version
- Adding Updated Post Date PHP Custom Theme
- Adding Additional Variables on Menus Page
- Only load certain artists on this page
- Why the dynamic_sidebar() call is putted into an ul tag?
- Toolbar Hidden in a Virtual Page
- Class for Selected Menu using wp_nav_menu
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Header is not displaying on certain pages of wordpress theme [closed]
- Looping through dummy posts and showing them in the main index.php
- ACF – Get ID of relationship field in flexible content
- Replace an array (with identical values) with another array in the_content
- Warning: count(): syntax problem of the count () function
- PHP warning with code for nav menu walker [duplicate]
- String replace for Login/Logout concatenation problem in menu
- Customizer: How to Sanitize a Decimal Number Range
- PHP code printed into CSS classes
- Get the image title and alt from custom query
- What syntax is this? “{{post.price}}”
- Page returning ID from array, how to return the correct values for post in acf wordpress
- wp_nav_menu prints children with parent name
- WP Admin Bar – Get current theme name as custom menu title
- WordPress get_post_meta issue
- Unserializeing multiple column values that are stored in one database results variable
- How to add button to top of theme customizer?
- get_permalink returning first letter
- Submenu opened problem
- Sidebar doesnt get updated?
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Predefine Magazine Style Layouts
- Twig+WordPress how to use array arguments inside a function?
- How to store the_post_thumbnail() value in a variable
- Grabbing value of input field inside of array
- Variable ++ in query loop