Default usage of add_filter
looks like this:
add_filter( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
As you can see, the default priority is 10 and by default only one param is passed.
In your code you need your filter to get 2 params, because wp_nav_menu_items
takes 2 params ($items
and $args
) and you need both of them in your filter. So you have to pass 2 as number of params, when you add your filter:
function add_new_item_to_menu( $items, $args ) {
if ( 'header-menu' == $args->theme_location ) {
$items .= '<li><a>Show whatever</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_new_item_to_menu', 10, 2 );
Related Posts:
- How to add nav menu items to a specific position within a menu
- Replace a menu with widget or a custom template file programmatically
- Filter nav menu items HTML tags and wrap inner text with span
- search form leads to 404
- Conditional custom menu?
- How to display an image before title text in menu items
- Function Reference for custom link in Admin Menu Management Page
- How to add a data attribute to a WordPress menu item
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Removing default image size list in Media Box
- How to restrict actions and filters “properly” by conditions
- syntax for remove_filter in parent theme with class
- Custom menus displaying all pages instead of set pages
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- Hide some items from Screen options in dashboard for products
- Editing or filtering the output of the Genesis navigation
- Replace Archive Widget Link Text
- Exclude Empty Child Categories in Menu
- Best way to programatically add “rel” attributes to page and post images
- add_filter priority problem
- Clean-up script tags
- Remove function or filter
- Super simple shortcode not working
- How to filter out shortcode when displaying the_excerpt() in the loop?
- Logout hyperlink within a sub-menu
- CSS for menu item added via functions.php
- Adding multiple taxonomy filters to functions.php
- Last updated date function
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- How to set default archive image without overriding first attached image? [closed]
- Make parent page only link to first subpage
- Only let plugin add actions to wp_head & wp_footer on single posts
- Hard-coding custom menu elements for menu manager
- Add data attribute to each li in menu
- How to make custom column Admin>Users sortable?
- Get Current Post ID in functions php, meta query filter
- Output and filter data from a XML url
- What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?
- How to fetch the name of the active menu?
- How to filter $content in shortcode function
- Filtering out the #more anchor link that gets produced by
- Add item to top of menu using a filter in functions.php
- Add Element as a Filter to the_content
- How can I add a filter for specific categories on functions.php?
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- Can’t properly set the_title add_filter to show short_URL
- Filter an WordPress Function in (general-template.php)
- How do I hook into the container of wp_nav_menu?
- How can I add a class to a nav li depending on URL?
- Nav menus all outputting the same links
- Secondary Menu and Logged In Users
- Modify gform_other_choice_value for specific form and specific field in Gravity Forms
- Change menu based on page template via functions.php
- Show some menu sub items as dropdown under a menu item
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- Different methods of adding menu support to custom theme
- Add Adsense code between job listings – wp job manager plugin
- Problem with images URL after filter applying
- remove_action not working, even after changing priority [duplicate]
- remove/hide wp-editor
- How to register a menu based on a ACF condition
- How to hightlight all ancestor menu items of a child page NOT displayed in menu
- Replace header image on all other pages but home – URL issue
- Add a class to post if it has been recently updated
- how to add_filter to non hook function
- How Can I add a menu to the theme from withen the function.php file
- define css class in functions.php
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- how can I add filter in specfic field in my website?
- Customizing the wp_video_shortcode output with add_filter
- Overwrite text in a complicated filter hook
- How to add HTML into error message
- Save_post – Warning: Cannot modify header information
- custom error message for empty username and password using authenticate filter not working
- Add #primary at the end of navlink permalinks on single posts
- remove_filter function to unhook twentysixteen parent theme function
- only update titles of single posts
- OOP Switch statement with array as parameter
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- How to add class dynamically from templates
- function replace_text for entire page
- ACF Filter return value
- Graphic before title – Specific Category
- How to make an If Else on Excerpt Filter
- Regex works in regexr, but not if I filter content [closed]
- Retrieve a custom form field modified by a filter
- functions.php filters not applied in AJAX call
- Adding custom field in menu options [duplicate]
- Settings in functions.php used by a plugin
- Adding a filter with custom function to the menu / navigation
- Can’t change excerpt length and more tag
- Force resize for all video content
- Way of getting queried loop before the query with a filter hook?
- Notice: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in ….functions.php on line 73
- Trying to get this function to show below the content
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- How to add more than one menu for logged in members?