If you want to exclude menu items by their labels:
function hide_menu_items( $items ) {
$items_to_exclude = ['Menu Item 1', 'Menu Item 2'];
if ( !current_user_can( 'manage_options' ) ) foreach ($items as $key => $item) if ( in_array( $item->title, $items_to_exclude ) ) unset( $items[$key] );
return $items;
}
add_filter( 'wp_get_nav_menu_items', 'hide_menu_items', 20 );
Related Posts:
- Testing requested query in pre_get_posts
- How to auto-translate custom user roles?
- How to make post and comment count unclickable with dashboard_glance_items hook
- wp_link_pages output appears twice
- How To Get User Data in Callback Function for pre_user_nicename?
- How to edit dashboard search posts button texts for my CPT?
- How to allow users to view pending posts of a specific custom post type?
- add_filter(‘the_content’, ‘…’) stops pagination from working
- upload_files cap to not loggen in users – add_cap to not logged in users
- How to add attributes to WordPress Admin Sub Menu List Items
- Why current_user_can(‘edit_comment’) always true?
- Why does admin_body_class not work?
- Dashboard filter based on custom fields URL response code
- How to allow suscriber to access specific pages in dashboard?
- WP Dashboard -> Posts-> Filter > BUG!
- How to filter reading/visibility posts based on role?
- How to make the show as a button?
- Removing Admin Bar Node Based on Role
- Code restricted to dashboard, running unexpectedly in the frontend (pre_get_post and admin-ajax.php)
- Filter and validate user role in registration
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- Filter dashboard custom post listing by user
- Block Gutenberg Editor manually by User Roles with a Filter with code
- Filter hook for the action of listing users
- Disable emojicons introduced with WP 4.2
- How to remove a filter that is an anonymous object?
- Changing Admin Menu Labels
- WordPress hooks/filters insert before content or after title
- How to add defer=”defer” tag in plugin javascripts?
- add_action(), add_filter() before or after function
- apply_filters(‘the_content’, $content) vs do_shortcode($content)
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- What is the very earliest action hook you can call?
- How would one modify the filtering Gutenberg applies to pasted content?
- How to elect position of new item output in a dropdown when using add_filter
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Replacing text using add_filter
- Using two posts_orderby add_filter makes conflict
- Background color and background image below element in Contact Form 7 – error tip [closed]
- Query Multiple Filters, one with Meta
- How to remove a filter that is an object method?
- Passing value from one hook to another
- Deregister Custom the_title Filter for edit_post_link
- custom post filter based on Visitors country
- Filter a custom post type by custom field in admin
- How to correctly override a filter?
- Limit total tags in the_content
- Is there a way to check if the ‘wp_sitemaps_enabled’ is true or false?
- How to use filter in this situation, can not modify the structure using filter
- Is it possible to dynamically change the “page_for_posts” option?
- Change password reqts with NO plugin without breaking resetpass link?
- Using the REST API filter, including two meta_queries breaks the response for one custom post type
- How can I conditionally add the filter option_home?
- Search and Filter Using Custom Post Type, Custom Taxonomy, and Advanced Custom Fields
- Adding filter to the Contact Form 7 response
- Remove rel=”ugc” from links in comments
- posts_results filter – additional sort, with a meta value, to move posts to the end of the results, with pagination working
- How to use parse_query() to add an additional filter based on content to page search?
- FacetWP was unable to auto-detect the post listing : Having an issue with ACF load choices causing FacetWP error
- How to change content hash value, within the_block_template_skip_link action?
- add_filter – create_function pb in PHP8
- Import bootstrap 5 and bootstrap icons in wp-admin backend
- How to apply_filter / add_filter within 2 others (simultaneous?) add_filter
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?
- Change or replace user_profile_picture_description filter, to stop stripping whitespace
- Woocommerce price filter widget always shows max price of most expensive product in the whole shop
- remove_function method removing next priority action too while removing current priority
- Are blocks that are converted to patterns no longer filterable through the_content?
- How to use add_filter to add the extra data to existing array?
- wc_get_template_part filter not working
- hook on the_excerpt
- Deactivate code made with add_filter
- Why wordpress doesn’t allow to add author filter to media library page in grid mode
- ‘Problem’ with login_redirect filter – why does it lose the redirect_to parameter
- Is there a way to override only a portion of the function print_media_templates defined in wp-includes\media-template.php?
- How could I create real-time filtering in this case?
- How to filter products by category in custom loop
- How to use render_block filter in Gutenberg when editing a page?
- WordPress REST API and Backbone JS
- “Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter
- How do I query Pending posts?
- How to override hook from themes functions.php which is defined in plugin
- How to increase comment length?
- Load More : Admin Ajax 400 Bad request, returning 0
- wp reset password page – head inline script
- add_filter( ‘user_has_cap’,’my_function’, 10, 3 ); and call to get_users in my function triggers an infinite loop in user list
- Custom updater to change plugin version
- Adding custom filter not working
- Core/Image access caption in render_template and in wp.hooks
- Ship block templates or block template parts with plugins
- How to add custom field to top of WordPress Comment Form for both logged in and anon users
- Is it possible to modify a WP search query to return results for private pages when not logged in?
- AAPF Filter group is not in widget section
- How can I inject an SVG gradient into the site/theme editor’s head or footer?
- Checking for stock in accordance with product’s SKU
- How to add placeholder into comment form textarea?
- Modify Gutenberg blocks quick inserter defaults