Not sure this is the simplest means, but you could conditionally add the filter to just the location you want to modify via wp_nav_menu_args
filter when wp_nav_menu
is called, then immediately remove the filter so it isn’t applied to other menus.
function wpa108544_nav_menu_args( $args ){
// check if it's the location we want the filter applied to
if( 'primary' == $args['theme_location'] )
add_filter( 'wp_get_nav_menu_items', 'wpa108544_get_nav_menu_items', 10, 3 );
return $args;
}
add_filter( 'wp_nav_menu_args', 'wpa108544_nav_menu_args' );
function wpa108544_get_nav_menu_items( $items, $menu, $args ){
// remove the filter
remove_filter( current_filter(), __FUNCTION__, 10, 3 );
// do your menu manipulation stuff here
}
Related Posts:
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- function triggered by “manage_users_custom_column” filter not working
- Some nav-menu filters do nothing
- Dynamically Override Fancy Title
- What is the difference between current_page_parent and current_page_ancestor?
- Does add_filter work outside functions.php
- WordPress after content Hook & external template part
- get_current_screen() return null
- Remove unwanted elements for a wp_nav_menu
- How do I access the menus produced by Dashboard > Appearance > Menus
- WordPress class, using add_action to call member function does not work
- Redirect to another page using contact form 7? [closed]
- Call to undefined function is_home() or any conditional tags
- WP_NAV_MENU filter targets all menus
- Adding tables to dashboard pages programmatically?
- Override category archive page title (not the head title)
- WordPress permalink setting
- How can I load a page template from a plugin?
- Add Dividers or Separators Between Nav Menu Items
- How to get Post ID with the Add Filter Function
- Overwriting Core WordPress Functions with Plugins
- Filter on the_content ignores shortcodes
- Display only certain posts based on visitor’s country?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- Hook event for upload image in the menu
- Problem with `wp_mail()`
- Calling a function from functions.php in custom page/ blog post
- What is the Difference between directly call a function and call a function using add_action?
- How do I approach removing menu items on the fly based on settings in my plugin?
- Call to undefined function get_blog_option()
- Changing bloginfo description from a plugin
- Undefined function wp_set_password
- Add Submenu Link in add_submenu_page That Opens in a New Window
- Plugin Uninstall and Deactivate via Options Menu
- How to assign a WP 3.0 custom nav menu to a theme’s navigation menu location via script?
- How to add pages to custom menus on the fly [duplicate]
- How can I add a CSS rule to edit.php?
- How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?
- add_filter : Passing an array instead of the callback function?
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- How to use WP_Term with (menu) argument in the wp_nav_menu?
- WordPress is automatically linking plain text email addresses
- add_rewrite_rule works in themes function php but when moved into plugin it stops working
- Where can i find wordpress auto update code flows?
- how to search users by ajax live search
- Can’t get woocommerce_get_price_html to work [closed]
- Is this best practice for Dynamically adding items to WordPress menus?
- WordPress custom taxonomy check box to dropdown
- mysql_real_escape_string() vs. esc_sql() in WordPress
- Using ob_get_content to get_search_form puts into infinite loop
- Checking for existence of a page by title?
- how to get context information inside my funcion
- How to modify files inside wp-includes directory in wordpress
- Fatal error: Call to a member function get_page_permastruct() on a non-object
- wp_get_post_terms Order by not working
- Add item to top of menu using a filter in functions.php
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Autogenerate a Table of Contents
- WordPress multisite,use same cookies across all website?
- Filter nav menu items HTML tags and wrap inner text with span
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- unregister_setting() vs delete_option() for plugin update
- How to add custom li item to wordpress menu
- wp_schedule_event is registered but function isn’t running
- How to add Plugin functionality in WordPress Frontend Menus
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- How to hide page links from theme menu
- How do I add a menu item to a Pods admin menu?
- Conditional custom menu?
- WP 3-way voting system: On to something! Please help!
- Custom Settings Plugin Save foreach checkboxes
- How to display an image before title text in menu items
- Limit get_next_post to posts from the same author
- WordPress: I wanted to use Add rewrite rule multiple times for multiple CPT in my plugin
- Any way, hook to add content right before the “read more” link?
- WordPress Ajax not returning Response
- Remove tag from all posts when publishing new post
- Redirect theme directory to plugin theme directory
- Modify search form with plugin
- Single_template for a custom post type created from a plugin is returning an empty page
- foreach argument to get specific file types getting too many returns
- WordPress Add advertising ads befor and after content with periority [closed]
- How to get an array out of a nav menu if it’s a plugin?
- Remove from a div by class name from post page if post author role is not administrator
- Confusing $tag specification for apply_filters call, in core options.php code
- Ajax not working to insert, query and result data
- How can I add recent posts to menu like mashable
- Why is ‘register_activation_hook’ undefined?
- Adding parent custom post type menu option
- Function Reference for custom link in Admin Menu Management Page
- How can i call from custom fields to the category editor?
- Apply Filters Causing a 500 Internal Server Error
- add_filter adds output in the head
- Apply function on all action hooks?
- How to plugin function code move to theme function.php ? I’ve tried below code but not working [closed]
- WordPress simple ‘Hello World’ plugin – problems
- Custom Nav Walker $item->url producing malformed hyperlinks
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- Ninja Forms: Front-End Forms, Post ID?