Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hide admin menu items on a WordPress site.
<?php
/*
The code below hides the admin menu items for all users that don't have the 'manage_sites' capability.
On multisite that would mean only Super Admins can look at those menu items
This script only removes the menu items so users can still look at the page if they know the path, but it de-clutters the admin
*/
global $current_user;
if ( !current_user_can('manage_sites') ) {
add_action( 'admin_menu', 'bones_my_remove_menu_pages', 9999 );
function bones_my_remove_menu_pages() {
global $menu;
//regular expression of menu items that need removing (by name/label)
$page_labels = "#(Forms|Custom Types|Appearance|Plugins|Tools|Settings|Performance|WPide|Seo)#i";
foreach ( $menu as $i => $item ) {
if ( preg_match($page_labels, $item[0]) >0 ) {
unset( $menu[$i] );
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment