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
- How to get shortcode’s input values inside a filter?
- How to bulk delete all users with no posts?
- WordPress 3.9 – Trouble Editing TinyMCE 4.0
- How to use update_{$meta_type}_metadata filter to modify meta value
- How to wrap an element around an iframe or embed in content automatically?
- Earliest hook to reliably get $post/$posts
- Modify links when inserted by WYSIWYG editor
- How to check if a hook is hooked or not?
- Completely strip any hidden formatting when pasting into TinyMCE
- How to add filter to __() and _e()?
- Include a page template along with add_theme_support()
- Make sub menu items a main link in the admin menu using fuctions.php
- WordPress Rest filter for custom taxonomy gets applied to the admin area
- add class to internal links in content
- Am I using the right hook for removing quicktags on the admin TinyMCE?
- Help debugging PHP filter for wordpress [closed]
- About Hooks and Filters
- How to link current user to their author page through shortcodes
- filter title from shortcode
- Add a Span Around a Product Title in WooCommerce [closed]
- How to get list of all hooks of current theme / plugin?
- get_query stops working after post filter
- How to filter into post meta data before saving
- Adding custom column to comments admin panel?
- Set default page for user account in admin
- is there a specific place where add_filter must be placed?
- add_filter() function misunderstanding
- How to make a widget expand wider than the column width when editing its settings in the admin
- Is there a wildcard/catchall filter hook?
- Apply the_content filter, but prevent other hooked actions
- Can the wp_filter object hold multiple values with the same key
- apply_filters/do_action tag characters limit
- the_excerpt filter with an empty excerpt
- Add Defer Attributes to WordPress Scripts with consistent versioning
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- String regex match replace for role ‘contributor’ only
- Can plugins that filter post contents work on posts from Word 2007?
- Better extend a class or use add filter/action hooks?
- Adding a Clone link to product attributes – post_row_actions() filter, or how to override a Class question
- wp_upload_bits Upload Specific Sizes Only
- how to customize rss feed tags using hooks?
- how to use force_filtered_html_on_import in add_filter?
- Filter Hook callback error, is it due to using $this inside a filter or something else?
- Disadvantage of using filters & hooks multiple times
- How To Override A WooCommerce AJAX Function
- Can I override the content array using the_posts filter?
- How to use do_shortcode_tag to modify the output of a shortcode?
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- How to trim white space in search terms?
- Changing the argument of a function
- Alter existing page contents based on url
- How to include add_filter() in a condition based on $post data
- Remove pretty photo style and script if not exist!
- custom gallery filter with image caption as link title?
- Is this hook really deprecated? ( manage_{$taxonomy}_custom_column )
- How do I modify the user role ‘subscriber’ to allow the user to delete posts
- The gettext hook doesnt work on text with links
- the_content getting current page content instead specified ID
- “The editor has encountered an unexpected error” After add defer tag to java script
- add_action with associative array
- Why does wp_die() not work when inside a namespace?
- Remove image of srcset
- adding existing menu page on new customer user role
- Set post featured image to author image
- Take filter from multiple functions
- Custom user roles
- Read More in the actual excerpt
- WP REST API v2. filters doesn’t work
- Is it possible to include the add_filter() function within a shortcode function
- filter on the_content stopped working when I updated to WP 3.6.1
- Replace Paid Shipping Method With Free Shipping Method WooCommerce [duplicate]
- Clean/filter HTML inserted to post content by XML RPC
- Is it possible to make get variable out of filter in Class?
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?