You could try the following code snippet to override the primary menu:
/**
* Override the primary menu.
*
* @param string $nav_menu The HTML content for the navigation menu.
* @param array $args Array of wp_nav_menu() arguments.
* @return string $nav_menu
*/
function wpse_150003( $nav_menu, $args )
{
//Override the primary menu:
if( 'primary' === $args->theme_location )
$nav_menu = 'My new menu';
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'wpse_150003', PHP_INT_MAX, 2 );
where we find the input arguments info from the source.
Notice that we return the $nav_menu
value, instead of echoing it.
You could also filter my other attributes, for example menu_id
.
You might also consider these filters:
wp_nav_menu_items
wp_nav_menu_{$menu->slug}_items
I hope this helps.
Related Posts:
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- Some nav-menu filters do nothing
- Determine which theme location a wp_get_nav_menu_items is for
- How do I access the menus produced by Dashboard > Appearance > Menus
- add_menu_page() with different name for first submenu item
- Difference Between Filter and Action Hooks?
- How to create an API for my plugin?
- Change the_title() of a page dynamically
- How do I programatically insert a new menu item?
- Using query_vars filter
- Nav Menu meta failing to import
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How Can I Add a Filter to Class Instance Only?
- Is it possible to remove next-post / previous-post with out creating a custom template?
- How do I Make a Theme “plugin-ready”?
- Proper way to use apply_filters() with class functions?
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Display only certain posts based on visitor’s country?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Conditional add_filter?
- Is it possible to create an action hook using do_action() within add_action()?
- Calling apply_filters on non-documented hooks
- Hook event for upload image in the menu
- How to allow Unfiltered HTML in a wordpress multisite install
- Why isn’t the Settings API designed to work for plugins using custom admin menus? [duplicate]
- Is there a way to verified if an add_filter is already applied?
- Define a function outside a class and call the function using action or filter hook
- Does add_filter work outside functions.php
- Synchronize Custom post type tags to WordPress default posts tags
- Delete a specific item menu when I deactivate my plugin
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Create a Page via plugin
- How to assign a WP 3.0 custom nav menu to a theme’s navigation menu location via script?
- PHP 7 – Class Method Compatibility Issue
- How to add pages to custom menus on the fly [duplicate]
- Add notification bubble notice in navigation using transients
- add_filter : Passing an array instead of the callback function?
- Namespaced action and filter tags
- Two functions utilizing registration_errors filter
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- WordPress is automatically linking plain text email addresses
- Add code inside specific wordpress standard function
- Adding custom fields to WordPress nav menus
- Sub Menu content is being duplicated
- Why doesn’t my simple the_title filter get applied?
- How to filter the_content() & include content from template
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Remove unwanted elements for a wp_nav_menu
- Can’t get woocommerce_get_price_html to work [closed]
- Is this best practice for Dynamically adding items to WordPress menus?
- Search and Filter
- How to remove or add submenu item on plugin activate or deactive
- WordPress custom taxonomy check box to dropdown
- wordpress add_submenu_page adds broken link
- Remove an action by extending class and replacing it
- WP Enqueue style on all plug-in pages
- Bind a function with its own argument to show something dynamically after every content
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Hook add_attachment error
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Issue with plugin sub menu and pages
- How to add Plugin functionality in WordPress Frontend Menus
- Gravity Forms Anchor only on Front Page?
- How to find list of all functions bind to a particular hook from my plugin?
- How to hide page links from theme menu
- Adding filter to the title without affecting the menu title
- How to validate inputs with filter in register_setting callback
- How do i remove the title from a specific page
- Can / should a widget plugin define its own Widget Area?
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- How to create archive page to add in menu
- add_filter postbox_classes multiple post types
- Override category archive page title (not the head title)
- Override woocommerce loop-start.php from theme using plugin?
- Always hide a page from the menu
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Change Front page displays settings conditionally when user is online
- Add_action not calling callback function
- I have a plugin where in I have to change the title of the page dynamically by sending parameter to the_title filter
- Custom signature appears twice on page
- Caption Shortcode: what filter to change the image size?
- Hook for plugin to show content for certain urls
- WordPress permalink setting
- What happens when you create/edit a menu
- Create and style menu
- Change the class of wordpress menu
- wp_mail_from not changing from address
- append code after the_content not working
- Invalid Menu Items
- Declaration of mandoe_menu_walker::start_el(&$output, $item, $depth, $args) must be compatible with Walker::start_el(…)
- Custom Nav Walker $item->url producing malformed hyperlinks
- Displaying an Uploaded Image as a Custom Avatar in WordPress