I’m reworking a client’s site and am replacing their functions.php. In there, I found a function that I wrote to remove specific menu items from the WordPress Administrative area. For future reference, here it is:
/**
* Several menus items are shown to non-Administrators, but really should not
* be displayed. Hide specific menus unnecessary for non-Administrators.
*/
function hide_admin_menus()
{
// If the user is not an Administrator, put together the pages that should not be displayed. To get the
// IDs, use the "id" attribute on the "li" element - if you right-click on any of the Admin menus and
// "Inspect Element" in Chrome, you can easily find it. The markup looks something like this:
//
// <li class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-plugins" id="menu-plugins">
//
// In the above case, the ID that this function is looking for is "menu-plugins".
$pages_to_hide = array();
if ( !current_user_can( 'manage_options' ) )
{
$pages_to_hide[] = 'toplevel_page_wpcf7';
$pages_to_hide[] = 'menu-posts-dt_portfolio';
$pages_to_hide[] = 'menu-posts-dt_benefits';
$pages_to_hide[] = 'menu-posts-dt_gallery';
$pages_to_hide[] = 'menu-posts-dt_slideshow';
$pages_to_hide[] = 'menu-tools';
}
// Now that we have a list of pages, run through them
// and hide them using CSS.
foreach ( $pages_to_hide as $page_to_hide )
{
echo
'<style>'.
'#'.$page_to_hide.' { display: none; }'.
'</style>';
}
}
add_action( 'admin_head', 'hide_admin_menus' );