You must return the value of a filter instead of echoing it…
Example:
add_filter('wp_nav_menu_items', function($items, $args) {
$link = '<li>Login</li>';
return $items . $link;
}, 20, 2);
The above will effect all menus however, instead use the $args variable to conditionally modify a specific menu only or use "wp_nav_menu_{$menu->slug}_items" which will only operatae on a specific menu, where $menu->slug is the key value passed to register_nav_menus or register_nav_menu
Recommended reading:
- https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/nav-menu-template.php#L418
- https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/nav-menu-template.php#L429
- https://codex.wordpress.org/Function_Reference/register_nav_menus
- https://codex.wordpress.org/Function_Reference/register_nav_menu
Related Posts:
- Woocommerce – adding variations to variations [closed]
- Passing a parameter to filter and action functions
- Do deactivated plugins slow down a WordPress site?
- Can YOAST SEO fields be removed from custom post type [duplicate]
- Allow all file types for upload
- Difference between a theme and a plugin?
- Creating Unique Post URLs for A/B Testing… Is this even possible?
- Change Label for field used in Woo Commerce
- Symlinked plugin directory doesn’t appear in Admin
- Suggest a plugin for up/down voting posts [closed]
- How to disable Gutenberg editor?
- How to install plugins in individual sites on a wordpress network?
- Get Latest Plugin Version from WP API
- Can’t install local plugin (zip) with wp-cli [closed]
- Cropping, Re-sizing and Saving images from one folder to another folder in wordpress
- Cron Job not working in plugin
- How to get all attachment image from post ?? WordPress
- How to check if I am displaying categories on a Woocommerce page? [closed]
- What plugin should I use for a basic user signup/login system [closed]
- Stop the form of beign submitted on “Save changes” custom option page
- How to avoid redefining requirejs in plugin when another plugin also uses requirejs
- Review plugin with rating of post [closed]
- WordPress with Composer and different plugins for dev/live.
- Can I use the same textdomain in two separate plugins?
- Is there a way to make a pure vanila page of just HTML/CSS/JS
- get_plugins() doesn’t work after plugins_loaded
- Getting user roles in plugin files
- Plugin and theme script load order
- How to import featured image using WP Rest API from another WP installation
- New to wordpress: would like to have pluggable main page sections [closed]
- How to save post change url youtube link?
- How make a php script run only with wp-cron
- Plugin Handle URL With Custom Theme
- CMB2 toolkit: Compare 2 Dates and validate the Time
- Where does the cookie mo_page_views_counter come from?
- auto populate list of questions if user select a category xyz
- Change commission_status paid when withdraw_status vendor is completed
- How to add tags in Submenu page or Menu page
- How to display taxonomy images with wp_list_categories?
- How to use is_single and get_post_type within a plugin?
- Getting a “Warning: call_user_func_array()” error whenever I install/update a plugin
- What is wordpress way to access a plugin’s classes/models to load custom post type data?
- Change wp-login to custom URL login page
- How do I get a post author’s image/avatar via RSS from another blog?
- Shortcode not getting replaced
- what is name of this plugin used for photo gallery page [closed]
- Why can’t I call a (member) function from within a foreach?
- Plugin that will output submitted form data for user? [closed]
- WordPress plugin to auto execute php script on a specific time?
- Vulnerability Concern From the Plugin or From Not Updating the Plugin?
- How to import WordPress site to new WordPress site?
- Why does this code snippet create a critical error on my site? [closed]
- Custom Font Complications (WordPress) [closed]
- How does translation (gettext) work for translating config file of plugin?
- Must use Plugin not updating HTML code in head
- Restore with Duplicator, URL is concatenated twice
- Installing plug ins on a wordpress hosted site
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- using wp_footer hook in a plugin
- WordPress “Add new tag” button is not working
- Which is a better practice when writing shortcodes: pack lots of configuration parameters or just give an id?
- I’m looking for a plugin to execute a specific task a certain time
- jQuery gallery plugin to interface with Picasa
- Looking for a photo gallery plugin [closed]
- Want to create custom design of progress indicator in wpforms
- In a WPMU that uses several different domains, how to enable users to register subdomains of any domain from the main site?
- Open_basedir errors – But setting basedir to none redults in 502 Bad Gateway
- Update automatically a form inside a function of a plugin
- How to prepare (compress/zip) a plugin to enable updating instead of adding new instance?
- add a hook of Woocommerce to a plugin but it only shows and doesn’t function properly
- Change language in SiteOrigin Widgets
- Include my files in a plugin? [duplicate]
- Some Widgets in the Right Side Bar and the whole Footer section is not working in a WordPress Site
- How to call a function from inside class to outside class
- Send email when a user registers Rest api
- Return function results within shortcode
- There was a problem uploading the cover image in buddypress, while uploading profile image?
- WP-CLI plugin delete command fails silently
- Frontend is empty wordpress
- “Share” Content from Another Site as Post
- WP plugin calls for custom pages
- Javascript in plugin not working
- Jetpack Comments Change Placeholder Text
- shortcode which is introduced into entry the blog, and appears in side bar
- import a latest vimeo user video into a page
- Create user assessment and use results in sql query
- Google Language Translator – Manage Translation
- WordPress multisite haml templates
- Modify plugin and submit to directory
- Sort Reviews/Ratings by date on Woocommerce
- Is it safe to increase/alter the size of the wp_post.guid column from VARCHAR(255) to VARCHAR(2048)?
- correct validate inputs
- How to add a text in the checkout page woocomerce?
- Automatically create WooCommerce products page by just uploading the images [closed]
- Multiple plugins settings of same developer into ONE settings page linked together
- all plug-ins load scripts on all pages
- Fields are not displayed on front end under custom php code in Advanced Custom Fields and Flexible Content field WordPress
- Automatically download dependent plugins from WordPress.org?
- Automatically install bundled plugins during theme activation?
- Webpack configuration for multiblock plugins behaves unexpectedly