You could work with a white-list and replace the regular expression with something more readable:
add_filter( 'nav_menu_css_class', function( $classes ) {
$allowed = [
'menu-item-has-children',
'current-menu-item'
];
return array_intersect( $classes, $allowed );
});
That would make it easier to maintain the white-list too.
Related Posts:
- Walker class: Problems with understanding how walk() method can be called without error
- How to Use the Function is_user_logged_in To Display Different Menus?
- How to create different menu’s for not logged in visitors and for logged in members?
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- create a select input with menus created on a custom options page
- Add data-id attribute to child page links
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- Featured image in menu wordpres
- How to get the count for each taxonomy term
- Function to return true if current page has child pages
- List of all theme customizer control types?
- Show the most popular post per week
- Add a class to links in the visual editor (how to get old dialog back)
- Creating custom Woocommerce attribute taxonomies from a plugin
- Remove/unset options field from backend Settings->General?
- Display posts by month
- How to preserve PHP modifications while upgrading WordPress?
- renaming an admin menu item with decimal array index number
- How can I hook into and edit the text of a wp_nav_menu tag?
- Removing jQuery migrate and working with dependencies
- Load post content into iframe
- is there a simple way to list every templates / php files used to generate a specific page?
- wp_customize_image_control default value
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- removing tags from wp_list_pages() using PHP
- Authenticating to WordPress, using my own authentication two-factor system
- How to add specific menu on a specific page or pages
- WordPress menu deletes when trying to add a hook
- Overriding a theme redux file in child theme
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Widgets not showing in my custom theme
- Creating new menu item
- How to display custom field on homepage
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- selected menu item
- How to get 2 or multiple custom post types in wordpress functions.php
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Creating bulk posts with Youtube videos
- Change the site tagline (or similar) based on current page
- Show comments menu in dashboard only if the site has comment
- Count top level menu items
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- How to pick the default selected value in wordpress dropdown?
- How to add a do_action on refreshing of WP customizer?
- Weird 404 URL Problem – domain name being placed at end of urls
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Replace shortcode in substring
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Add item to top of menu using a filter in functions.php
- Adding PHP in the menu
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Hook called before text widget save
- Echo title attribute php
- Automatically add images to a menu
- str_replace with the_content is not working
- Ajax search shows all results when user empties input?
- Need help with pagination
- How can I use custom menus with a Bootstrap WordPress theme?
- Adding Additional Variables on Menus Page
- Custom navigation menu with awsAccordion
- List of Events with Multiple Dates: Only NEXT Date
- Dynamic Menu drops pages?
- Editor capabilities – admin_init
- How to create Loop code for Menu using WordPress?
- WP insert post Redirect after function has executed
- Hide A Class and Add Custom HTML Code Using WordPress
- How to set Nav as a default menu in wordpress
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Dynamic “home” image and URL based on current folder
- Noob question: want to remove the “site identity” logo for specific part of website only
- PHP warning with code for nav menu walker [duplicate]
- String replace for Login/Logout concatenation problem in menu
- Bring Font Awesome icons inside menu A tags
- Autoloading Classes in Plugins
- Automatically refresh page if widget is added to page?
- Display specific main Sub Nav on Woocommerce product pages
- Show content by using tags
- WordPress error on my website
- WP Admin Bar – Get current theme name as custom menu title
- Use custom get results query to show posts WordPress
- media-uploader insert into post is not inserting
- Best way to define a database with product codes and back-end support?
- How to show all of aspecific post type that has taxonomy and a specific term
- How to hide something from custom home page with php code?
- How to add button to top of theme customizer?
- Display a list of users with avatar filterable with alphabets
- Custom Links in Walker Class
- How can I add more code to this?
- How does one programmatically manage posts from a external php script?
- Edit the Publish Widget Options
- WordPress menu links with images & class selection
- How to remove the intro animation which appears during the load up of some WordPress themes? [closed]
- New to WordPress & Freelancing [closed]
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0