Before being printed, all the menu items get run through a filter. You can target the wp_nav_menu_items
filter to tack things on to the menu:
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
$homelink = '<li class="home"><a href="' . home_url( "https://wordpress.stackexchange.com/" ) . '">' . __('Home') . '</a></li>';
// add the home link to the end of the menu
$items = $items . $homelink;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
Or, to be more specific, you can target only the desired menu by replacing the add_filter
line from above with the following, and replacing $menu->slug
with your menu’s actual slug name:
add_filter( 'wp_nav_menu_{$menu->slug}_items', 'new_nav_menu_items' );
Related Posts:
- add_menu_page() with different name for first submenu item
- How to add sub-menu to a menu generated by wp_nav_menu by using plugin
- Change the_title() of a page dynamically
- Add Dividers or Separators Between Nav Menu Items
- Nav Menu meta failing to import
- Overwriting Core WordPress Functions with Plugins
- Some nav-menu filters do nothing
- Determine which theme location a wp_get_nav_menu_items is for
- Can I add pages to my custom menu via script?
- Replacing WordPress menu functionality with a plugin
- Hook event for upload image in the menu
- Why isn’t the Settings API designed to work for plugins using custom admin menus? [duplicate]
- How do I approach removing menu items on the fly based on settings in my plugin?
- What is the difference between current_page_parent and current_page_ancestor?
- Delete a specific item menu when I deactivate my plugin
- Create a Page via plugin
- Add Submenu Link in add_submenu_page That Opens in a New Window
- How to assign a WP 3.0 custom nav menu to a theme’s navigation menu location via script?
- Header Button Chance Polylang Elementor
- PHP 7 – Class Method Compatibility Issue
- How to add pages to custom menus on the fly [duplicate]
- How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?
- Add notification bubble notice in navigation using transients
- Get Current Menu Location inside Nav_Walker
- Adding custom fields to WordPress nav menus
- Sub Menu content is being duplicated
- Plugin menu addition in multisite
- Remove unwanted elements for a wp_nav_menu
- Is this best practice for Dynamically adding items to WordPress menus?
- How to remove or add submenu item on plugin activate or deactive
- Custom code for WordPress dynamic menu
- How do I access the menus produced by Dashboard > Appearance > Menus
- wordpress add_submenu_page adds broken link
- WP Enqueue style on all plug-in pages
- Add child pages to submenu automatically
- Customize existing menu item
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Issue with plugin sub menu and pages
- How to add Plugin functionality in WordPress Frontend Menus
- How to hide page links from theme menu
- WP_NAV_MENU filter targets all menus
- How do I add a menu item to a Pods admin menu?
- Add user managable titles to custom menus?
- How to create archive page to add in menu
- How to show only the last two categories in a menu?
- Always hide a page from the menu
- remove different admin menu for specific users
- How to get an array out of a nav menu if it’s a plugin?
- What happens when you create/edit a menu
- Plugin admin list pages as submenu
- Adding parent custom post type menu option
- Create and style menu
- Change the class of wordpress menu
- 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
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- How can a plugin create a page/form in the front end?
- When wp_schedule_event action has two possible directions, how to avoid an infinite loop?
- The ideal place for storing persistent PHP objects
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- WP_Error handles errors, but how can I show success with a message?
- How to determine wordpress base path when wordpress core is not loaded
- Overwrite default XMLRPC function from plugin
- How to update total price of completed order in woocommerce? [closed]
- How should I store a log for my plugin
- what is the difference between these phares?
- WP_Query filters
- SSL certificate verify failed
- wordpress how to query wp_options table
- rest_no_route on custom API endpoint wordpress
- Multiple API Endpoints (wp_remote_get)
- plugin_dir_url & plugin_basename not working when plugin dir is outside wordpress dir
- How to replace default comments with custom HTML?
- Adding Amchart Interface to WordPress API
- Plugin with functions inside a class & how to trigger WP CRON
- add_settings_error on validating plugin options API
- Unable to show a message after plugin activation
- Ajax url value to pass ‘variable’ to use in query
- How to get the value entered in the input field in wordpres
- Sanitize and Save metabox values
- Help interpreting @wordpress/create-block-tutorial-template usage error
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- WooCommerce adds a newline symbol (\n) between email recipients
- Upload to a specific media folder created by FileBird Lite
- How can I add a custom button to the post editor?
- How to use register_setting()
- What’s wrong in the WordPress Meta Box Generator code?
- add category id to option name when adding an option on edit_category
- esc_url, esc_url_raw or sanitize_url?
- React Plugin Settings Page Localization
- Is it within WordPress guidelines to update another plugin’s database fields from my own plugin? [closed]
- Block Development: hamburger module throwing error in save function
- How can I chanage the user for the composer container in wp-env?
- Why isn’t custom sidebar panel not showing up in the Gutenberg Editor?
- Ninja Forms: Front-End Forms, Post ID?
- Allow HTML in product attributes and variation for WooCommerce
- How do I modify the error code array used by “shake_error_codes” filter?
- How do I add multiple custom menu Woo-commerce my account page?