To do that use the following function:
add_action( 'admin_menu', 'custom_menu_page_removing' );
function custom_menu_page_removing() {
global $pagenow;
if ( !current_user_can( 'administrator' ) ) {
$menu = array(
'edit.php',
'edit-comments.php'
);
foreach ( $menu as $main ) {
remove_menu_page( $main );
}
if ( in_array( $pagenow, $menu, true ) && ( !isset( $_GET['post_type'] ) || isset( $_GET['post_type'] ) && $_GET['post_type'] == 'post' ) ) {
wp_die( 'Access denied...' );
exit;
}
}
}
This will execute the function only if the user is not an admin. Where you see edit.php and edit-comments.php, you can replace and add more menu slug that you want to hide. Make sure you add a , after each one except for the last one.
Related Posts:
- How to Add a Third Level Sub Menu to the WordPress Admin Menu
- Admin menu as submenu from another plugin
- Creating a WordPress admin page without a menu for a plugin
- Removing an admin page added by a 3rd party plugin. Gravity forms in this example
- Delete option doesn’t appear for plugins
- Adding an admin page – OOP approach not working
- Generate Advanced Custom Fields box in custom admin menu page
- Plugin development: how to create a form and get custom data?
- Master menu item for multiple plugins?
- How to make a WP admin button/menu similar to Jetpack Notifications?
- wp_verify_nonce() why return false?
- Detecting when a custom taxonomy has been changed and display alert?
- Sub menu with a URL parameter and access the page
- Removing WordPress Plugin Menu Item for a specific user
- add function to saving change on Options Pages
- Change the $parent_file of a plugin page
- reorder plugin menu position
- How do I remove the entire left nav bar in admin for certain level users?
- Hide Theme options and Customize Admin menu
- How to send little data between admin pages of my plugin?
- how can I link to a PlugIn admin-sub-menu page after processing a formular
- White page on custom plugin option submit
- Show existing POST categories as items in the sidebar menu [closed]
- Polylang : Interverting languages after development [closed]
- Suggestions on Approach to New Plugin I’m Stuck On
- Dynamic admin submenu
- WP Plugins – Use includes to display page content
- Add menu page issues (permissions & position)
- How to use add_submenu_page() for editors?
- What’s causing this error? “Warning: Invalid argument”
- Move plugin-settings to ‘Settings’-menu in the admin
- Editing a text file from plugin menu
- WordPress Admin Menu defining function is seperate file
- creating a plug in that would tap into save/update action of posts [closed]
- Display Plugin Panels Outside of Admin Areas
- Why WP_Screeen doesn’t show all options with admin_body_class
- Plugin Admin Menu Boiler Plate
- add_submenu_page returns null
- Plugin – Admin menu page broken url
- How do I add an options page at the bottom of the list?
- How to remove a CPT Menu from the Root Admin only
- Show WordPress Plugin Menu(Admin) To Editor
- Add logo to admin menu in my plugin
- How do you add a settings page to another menu?
- Custom page in plugin visible in menu
- Adding custom Field To The Posts Listing
- Creating an admin button that when clicked shows a popup form
- add menu page not showing Icon
- Custom Icon assigned to menu items not working for multi-site networks
- Admin menu hilighting wrong item for CPT
- Creating Admin Submenu Page via Class Method
- Plugin option for input box validation
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- Assigning a custom post type to a custom page
- How can I pass value to function in add_menu_page?
- Getting 404 page not found error while trying to access add new plugin / themes
- Plugin menu replaced by another plugin?
- Plugin link does not appear in my toolbar
- admin_enqueue_scripts using hook_suffix vs GET page
- Submitting form to admin-post.php WordPress
- How to use classes declared in another plugin?
- Experiences with adding Nonces to the comment form
- How can I allow moderated anonymous contributors to post to my blog?
- Add rewrite rule to permalink structure
- Finding WordPress sites using my plugins
- WordPress 4.0 Cookie Authentication to avoid nonce error when publishing a post and page
- how to display all posts Custom fields dynamically?
- How to Build a Movie Library in WordPress 3.x
- Intercept comment form submit/list by hook/filter
- Apple push notification doesn’t work
- WordPress Ajax Posting from App
- Is any gallery plugin available to generate galleries from existing uploaded images? [closed]
- How Do I Figure Out What File(s) to Edit from Looking at the Source Code [closed]
- Change permalinks of custom post type ‘question’ as post id or any random number once
- Displaying Custom Sidebar Without Modifying Theme’s Core File?
- Anyway to convert a plugin to become a shortcode?
- How to automatically add edit link on frontpage post of any wordpress theme?
- Use different single.php file based on condition
- Change the style of h1, h2, only in post entry
- Pass user role to javascript code inside body
- Blog previews on custom page with more buttons
- Dropdown menu on click change
- How to turn my WordPress site into a ready to deploy template?
- Optimal image size for wordpress?
- How to add the search page link to the anchor tag?
- How to fetch WordPress database values in JavaScript widget
- Possible way of having multiple Gutenberg instances for a page?
- WordPress: Can’t connect to the Akismet servers
- Plugin updates, change file permissions on WordPress
- I am Getting Sorry, no posts matched your criteria on form submit only for certain page [duplicate]
- Dynamic input fields in WordPress Plugin
- Custom role not listed
- How to Prevent User From Submitting Property Or View His Posted Properties Before Login in wordpress?
- WP Rest API v2.0 user profile update issue
- plugins_loaded action is not working properly
- After installing plugins, changes don’t appear
- How to add a plugin in WordPress theme directory?
- wp insert post not working
- Hidden Elementor sections slow down website. How to fix this? [closed]
- Conclude woocommerce-shipping-totals