Hide admin menus from non-administrators
Users who aren’t administrators no longer see the Tools and Comments menus. Change the list to hide what your editors don’t need.
<?php
add_action(
'admin_menu',
static function () {
if ( current_user_can( 'manage_options' ) ) {
return;
}
foreach ( array( 'tools.php', 'edit-comments.php' ) as $page ) {
remove_menu_page( $page );
}
},
999
);
Good to know
This only hides the links: use roles and capabilities to really stop someone. Other menu files: upload.php (Media), edit.php?post_type=page (Pages), themes.php (Appearance), plugins.php, users.php, options-general.php.
In these packs
- More admin tweaks: Useful columns, a tidier admin bar, a welcome box for clients, and fewer menus for editors.