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
- Where can i find wordpress auto update code flows?
- Sub Menu content is being duplicated
- How to add nav menu items to a specific position within a menu
- Check for template part, else filter content
- Adding option to Gallery shortcode
- correct way to call javascript into hook function
- Plugin menu addition in multisite
- Why doesn’t my simple the_title filter get applied?
- How to filter the_content() & include content from template
- How can I remove a function that has been added to wordpress with add_filter?
- Adding rewrite rule dynamically
- How to change the hover content of a specific menu item on WordPress?
- Add data attribute to each li in menu
- how to search users by ajax live search
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Replace youtube embed in wordpress
- Can’t get woocommerce_get_price_html to work [closed]
- Is this best practice for Dynamically adding items to WordPress menus?
- How do I update a field of a meta box?
- Search and Filter
- How to remove or add submenu item on plugin activate or deactive
- How can I replace content in the WP Admin area before an admin page is rendered?
- Unique icons next to each WordPress menu item
- How to add user details to different tables immediately after user registration
- Replace a menu with widget or a custom template file programmatically
- How to filter content for specific content variable
- WordPress custom taxonomy check box to dropdown
- mysql_real_escape_string() vs. esc_sql() in WordPress
- Custom code for WordPress dynamic menu
- WordPress function get_the_terms() returns ‘Invalid taxonomy’ error
- Using ob_get_content to get_search_form puts into infinite loop
- Checking for existence of a page by title?
- Valid filenames for add_action’s first parameter
- 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
- How to get all queries’s results after they have executed?
- Function/Class to list categories with checkboxes
- How to get the post excerpt using post object?
- wp_get_theme Warning: Illegal offset type
- wordpress add_submenu_page adds broken link
- Check if variable is set in filter
- Why wp_die() doesn’t work with wp_redirect but exit() works
- Remove an action by extending class and replacing it
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- WP Enqueue style on all plug-in pages
- Add child pages to submenu automatically
- Print Dashboard submenu name and filename
- Autogenerate a Table of Contents
- Customize existing menu item
- hook filter after the_content on a specific page
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Bind a function with its own argument to show something dynamically after every content
- WordPress multisite,use same cookies across all website?
- Apply styles to blockquote element with the WYSIWYG editor
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Filter nav menu items HTML tags and wrap inner text with span
- Hook add_attachment error
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- unregister_setting() vs delete_option() for plugin update
- How to change WooCommerce loop product title HTML output in single product page and archive page
- Update variable value via add_filter
- How to add custom li item to wordpress menu
- Make wordpress join default user metas with a column from another table while displaying the wp_users table on the users screen
- How to output functions from plugin inside theme
- Issue with plugin sub menu and pages
- Configure WordPress to Generate Scheme-less Relative URLs
- wp_schedule_event is registered but function isn’t running
- How to add Plugin functionality in WordPress Frontend Menus
- Get the name of menu item with wp_nav_menu
- Gravity Forms Anchor only on Front Page?
- How to find list of all functions bind to a particular hook from my plugin?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- How to add aria role and schema markup to custom walker container
- Overwriting a plugin function
- Writing editor content to a file
- How to hide page links from theme menu
- search form leads to 404
- How do I add a menu item to a Pods admin menu?
- Adding filter to the title without affecting the menu title
- How to validate inputs with filter in register_setting callback