You would probably get at least equally good performance by simply adding the classes with a filter, and it is certainly neater and closer to the way the WordPress is meant to be modified:
function add_classes_wpse_190966($classes) {
if (in_array('current-menu-parent',$classes)) {
$classes[] = 'active';
}
return $classes;
}
add_filter('nav_menu_css_class','add_classes_wpse_190966');
Or, with an array of values:
function add_classes_wpse_190966($classes) {
$itemsToReplace = array(
'current-menu-parent' => 'current-menu-parent active',
'item' => 'name'
);
$classes = array_intersect_key(array_combine($classes,$classes),$itemsToReplace);
foreach ($classes as $v) {
$classes[] = $itemsToReplace[$v];
}
return $classes;
}
add_filter('nav_menu_css_class','add_classes_wpse_190966');
Related Posts:
- What effect does the_content filter have on performance?
- Are there Limitations on filter handles?
- Run oembed separately outside the_content()
- Is there a get_post(s) filter that can alter/replace the output completely?
- What hooks to hook onto for automatic cache clearing
- Pass debug_backtrace() in WordPress filter
- Most performant/functional way to add actions/filters?
- WordPress wp_lazy_loading_enabled returns loading attribute set to lazy
- Changing WooCommerce Display Price Based on User Role & Category [closed]
- How to add headers to outgoing email?
- LESS CSS enqueue_style with add_filter to change rel attribute
- Remove Editor From Homepage
- Remove description from on Home
- What do add_filters() and apply_filter() do?
- How can I detect if a user changes their password?
- What to use instead of the content_save_pre filter?
- Moving sharedaddy buttons (in Jetpack) to the top of a post?
- How can I customize the wp_list_categories
- How can I reliably and globally disable wptexturize?
- changing variable through filters or action hooks
- filter the_title problem in nav
- Add classname to the_category() function?
- Filter the URL of next_posts_link & previous_posts_link
- Sensei LMS Hooks to Remove Content
- How to re-enable a filter after disabling with __return_false
- Ignore dots when searching in the media library?
- Exclude One Category and its Subcategories using WP_LIST_FILTER
- Gutenberg disable the “block” tab in right sidebar
- Where is this inline CSS code [closed]
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- Why won’t my preg_replace work with content_save_pre?
- Echoing Categories only if they’re a child of a given category
- How Does comment_author Filter Work?
- Add ‘data-text’ attribute to TagCloud HTML
- Why in archive page doesn´t show read more button with excerpt?
- Removal of Jetpack OG Tags from old blog site
- Adding a title prefix with the the_title filter
- get_posts() and filters
- Don’t see add_filter result in the site front page
- How can I include an existing custom sitemaps listing in wp-sitemap.xml?
- Display Externally Retrieved Data within a Custom Template
- Can the wordpress color palettes by changed through Javascript?
- Filter on the_content doesn’t update the content being searched via register_rest_route
- Where to add_filter in theme functions.php?
- Cannot change the definition of AUTOMATIC_UPDATER_DISABLED
- How do I add a checkmark to my-sites save settings hook
- tag removed not using a filter
- Add Lightbox To WordPress Native Gallery
- WordPress Image update filter
- How to remove this filter?
- Trouble using remove_filter to override function in parent theme
- Load Posts’ individual body content on index starting at char 200 of each post
- How to combine multiple body classes
- Why does my site flash white every time it changes page? [closed]
- Prepending character(s) to a custom tag title?
- How to replace username with email address in users table
- Modify existing plugin function with add_filter
- include specific Pages to wp_list_pages with filter
- why require – does not load filter
- How can I filter tag_description()?
- Email Obfuscation: Is antispambot() Acceptable? [closed]
- an action hook when a post reaches a certain number of views
- WordPress overwrites UNC
- Need to return shortcode text instead of the output
- Repeated nav bar queries failing to be cached
- Excluding posts by meta, and also keeping posts without the meta
- Change tags url to search different site
- How to optionally append components to the output of a gutenberg block?
- Dashboard filter based on custom fields URL response code
- Custom SQL query slows down when using multiple OR … LIKE … in posts_where filter
- I want to add string array to this function to filter displayed option in drpodown [closed]
- Drop down filter sort posts by latest, last 7 days and monthly
- Function not returning correct value for found_posts filter
- Unable to defer loading of jquery
- Remove style tags from head
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- how to develop a filter in wordpress to let the user filter the page content depends on the date (newest to oldest etc…)?
- Print only parent categories of post in custom RSS feed
- Login logout below menu bar
- Use add_filter inside another function
- Add HTML to the bottom of each post in a post list
- How to filter reading/visibility posts based on role?
- Admin view: filter posts by whether they have specific taxonomy attached
- Filter posts by categories ajax is showing all the posts
- URL to filter posts by post meta similar to shop/?product_cat=”painting”
- Incrementing content with extra text after save/publish
- What scope is $blog_url = get_bloginfo() inside a function
- How to use a TinyMCE filter?
- Unable to get WordPress’s apply_filters(‘site_url’) to return a https scheme
- Remove action added from class
- Identify admin/logout and more filters
- Sanitizing a custom query’s clauses
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- How to create a list of terms who’s posts also have a predefined external term?
- How to elect position of new item output in a dropdown when using add_filter
- Query Multiple Filters, one with Meta
- How to remove a filter that is an object method?
- Filter a custom post type by custom field in admin