wordpress disable/remove menu submenus

<?php
add_action( '_admin_menu', 'disable_category_menu');

function disable_category_menu () {
global $submenu;
if (is_site_admin()) {
return;
} elseif(!empty($submenu['edit.php'])) {
foreach($submenu['edit.php'] as $key => $sm) {
if(__($sm[0]) == "Categories" || $sm[2] == "categories.php") {
unset($submenu['edit.php'][$key]);
break;
}
}
}
if (!empty($submenu['themes.php'])) {
foreach($submenu['themes.php'] as $key => $sm) {
if(__($sm[0]) == "Themes" || $sm[2] == "themes.php") {
unset($submenu['themes.php'][$key]);
break;
}
}
}
if (!empty($submenu['tools.php'])) {
foreach($submenu['tools.php'] as $key => $sm) {
if(__($sm[0]) == "Tools" || $sm[2] == "tools.php") {
unset($submenu['tools.php'][$key]);
break;
}
}
}
}

function remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Posts'), __('Media'),
__('Links'), __('Pages'), __('Appearance'), __('Tools'),
__('Users'), __('Settings'), __('Comments'), __('Plugins'));
if (is_site_admin()) {
return;
} else {
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
  unset($menu[key($menu)]);}
}
}
}
add_action('admin_menu', 'remove_menus');
?>
About these ads

About Kapil Chugh

In love with PHP and tweaking WordPress. Hungry for Open Source and new technologies. Honest. God-fearing. Happiest when solving problems.
This entry was posted in WordPress and tagged . Bookmark the permalink.

13 Responses to wordpress disable/remove menu submenus

  1. bim says:

    hi, i think your code only hides unwanted menu but still can access the designated URL for these hidden menu. just sharing what i’ve encountered.

    • sebastien says:

      yes it is, you’re rigt, but it’s ok for me. :-)
      And for the menu “editor” do you know it’s possible to disable this menu ?

  2. sebastien says:

    Hi. I want to hide only the submenu “Editor” in “appearance”… this submenu is adding by this line :
    // Add ‘Editor’ to the bottom of the Appearence menu.
    add_action(‘admin_menu’, ‘_add_themes_utility_last’, 101);
    function _add_themes_utility_last() {
    // Must use API on the admin_menu hook, direct modification is only possible on/before the _admin_menu hook
    add_submenu_page(‘themes.php’, _x(‘Editor’, ‘theme editor’), _x(‘Editor’, ‘theme editor’), ‘edit_themes’, ‘theme-editor.php’);
    }

    what can i hide this submenu please ?

  3. I’m using F-8 lite, and my menu disappeared when I updated something! Do you know how to get it to re-appear?

  4. A. R. says:

    I am new to wordpress, so thank you for your help. Where do i put this code on my wordpress page in order to remove the horizontal submenus on my pages? Do the code have to go on each page that I would like to remove the submenu for?

  5. Apoorva Moghey says:

    Fantastic trick to disable menu & sub-menu.It helps me allot .
    Thanks Kapil

  6. Thanks for sharing this. Now I can selectively choose which multisite users can access certain sub-menus (for instance I’ve disabled themes for standard users). This saved me some time hunting around on the web.

  7. Kapil Chugh says:

    For that you need to unset submenus.I have given code to remove submenus as well.

  8. Dominic Penrice says:

    how do I use this to show only a one level down of sub menus? Or how do I not allow certain pages not to appear the in menu at all.

    Many thanks for your help.

    Dom

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s