I’m running WordPress multisite 4.3 and I’m trying to remove some submenus from the Appearance menu for my site editors. I’ve had success with removing the fly-out links to ‘themes,’ ‘widgets,’ ‘menus’ and ‘customize’ with the code below, by creating a new capability and keying off that:
$cap = 'no_see_menus';
function edit_admin_menus() {
global $submenu;
if(!current_user_can($cap)){
remove_submenu_page('themes.php','themes.php');
remove_submenu_page('themes.php','widgets.php');
remove_submenu_page('themes.php','nav-menus.php');
remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php' );
}
}
add_action( 'admin_menu', 'edit_admin_menus' );
The problem comes when I try to remove links to the header and background customization, both of which have strings that include ampersands. But even after replacing ‘&’ with &
in the string, the function will not pick it up:
remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php&autofocus%5Bcontrol%5D=header_image' );
remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php&autofocus%5Bcontrol%5D=background_image' );
So I’m stuck here. I greatly appreciate any suggestions.
You can likely do it with css
display:none
. The trick will be using browser dev tools to determine if the submenus have unique enough id/class.I was able to accomplish what I needed with what I’m sure is a super cludgy method. I had to create one function for part of the menus and another to get rid of the custom header and custom background menus. Here it is in all its ugliness.
If anyone has a more elegant way to achieve this, by all means post it here. Thanks for the suggestions.