Hide Admin Menu Items From Non-Administrators
Removes selected menu entries (Tools and Comments by default) for every user who is not an administrator, to keep the admin menu focused.
Opens WPIDE on
Code
add_action( 'admin_menu', function () {
if ( current_user_can( 'manage_options' ) ) {
return;
}
// Menu slugs to hide. Examples: 'edit-comments.php', 'tools.php', 'upload.php', 'edit.php?post_type=page'.
$hidden = array( 'tools.php', 'edit-comments.php' );
foreach ( $hidden as $slug ) {
remove_menu_page( $slug );
}
}, 999 );
Notes
Hiding a menu item does not remove the permission; users can still open the screen by URL if their role allows it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.