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
- Not able to change wp_title using add_filter
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- Changing JPEG compression depending on image size
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- Insert Custom HTML After Shortcode
- Is there a way to add another row to the tinyMCE kitchen sink toggle?
- What do add_filters() and apply_filter() do?
- add_filter to youtube embeds?
- SSL certificate for the host could not be verified
- Store source permalink on XMLRPC calls
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- Can’t change a label in woocommerce with the normal filter
- WordPress RSS feed – filter RSS content by custom field value
- What is the filter hook for custom fields content?
- Filter keywords from search query
- Add classname to the_category() function?
- Filter the URL of next_posts_link & previous_posts_link
- How To Remove Dashboard Menu Items for Multisite Users?
- How to minimize WP dashboard menu programmatically?
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- Explanation for remove_filter used in the below code [closed]
- How to change the blog title with add_filter? details below
- Editing
- the_content filter – checking the post
- add_filter to apply_filters that exists within class
- Which built-in WordPress files are safe to edit?
- How do I target a single page to modify the comment form of only that page?
- Adding a title prefix with the the_title filter
- How to removes all instances of thumbnails displayed in my theme?
- Contact Form 7 filter similar to preprocess_comment [closed]
- How to modify an existing meta description?
- Adding TinyMCE buttons without removing plugin buttons?
- Dashboard menu missing
- Role capability issue
- How to customize the “Insert/edit link” popup box?
- How to filter backend post list showing only posts having a shortcode
- How do I override the_excerpt so that it will display full content?
- Why does WordPress strip custom HTML that are form elements and theme SVG icons?
- Get current user data
- How can you wrap add_filter with a if is_home() statement?
- How to combine multiple body classes
- How can I programattically hide all admin notices for everyone except admin users
- How to write a filter to remove a form field (WordPress) [closed]
- Why doesn’t this function work when I know that the IP Address is “true”?
- term_link filter rewrite link only applying half of condition?
- How to change dynamically page title according to variable data?
- Map plugin with proximity search compatible with Buddypress
- Create a pre-filtered version of the Media Library
- How to hide some categories in dashboard
- What is the action hook to use if you want to capture the new password during password change?
- Get_template_part inside filter?
- How to filter Sidebar Content
- Removing URL and adding container around image in the featured image metabox
- How would I use a filter to remove header banner on certain post types
- Replace Data In Post & Update Meta Field Post Is Saved
- How to add custom media library mime icons?
- Customising the default wordpress search functionality
- Block access to plugins.php for custom role
- Ajax filter – show all results that contain at least one filter
- Help Adding filter to Add Media button for custom post type
- Action for opening attachment or manipulating all attachment links
- Filter wp_mail based on content type
- Remove the post_content search from WHERE clause (and CONCAT sql function)
- mu-plugins body_class filter not working
- Post filter Month dropdown at front-end like wordpress backend
- shortcode function outputs multiple anchor tags
- Show child theme for users on specific IP
- wp.getPosts with status = ‘trash’ using node.js
- Is there a way to overwrite a filter used in canonical.php?
- How do I remove certain HTML elements with specific classes from the feed?
- confusion with add_filter
- post->post_content filter
- How to change this WP logo and posts url in block editor?
- Limit total tags in the_content