Remove WordPress Admin Menu Without Affecting WordPress Core System

In WordPress, each user type have different capability. Sometimes, we want to change these capability and the most easiest way to do that is to remove what they can see when they logged in. Especially when someone wants to change WordPress into a powerful CMS and remove certain admin menu without touching the core system. In most CMS, there are so much restriction on their core system that makes it really inflexible. Unlike other system, WordPress is able to modify their core codes using plugin without affecting the fundamental codes in WordPress. Hence, we can continue to upgrade our system without having to worry about updates that will kill your modification. In this article, i will show you how i remove WordPress admin menu using plugin style without affecting WordPress Core codes.

WordPress Admin Menu

If you are able to dig into WordPress code, you will notice that their menu is created by a single function using two global variables as parameter. You can easily find this code located at wp-admin/menu-header.php, line 157-158.

13 thoughts on “Remove WordPress Admin Menu Without Affecting WordPress Core System

  1. Great post Clay - I find that I have to do this every once in a while, and before finding your post, I often just did it by using some custom css to hide different parts of the admin menu - definitely a poor solution compared to accessing the menu array directly. Thanks!

  2. Nice solution! But how would you remove only a couple of submenu items without removing the topmenu, say I'd like to remove the categories submenu from the Post top menu..

  3. It should be quite easy from the look of the code. You can just place a set of array and only unset those sub menu in the array (using in array). Then, remove the main menu 'unset' so that all main menu remain there.

  4. Is there any centralized place where I can change the links to the different admin panels?

    I'd like to change the unset/remove for all menus/submenus for a dummy panel, changing the urls to "#".

    Thanks to you now I know how the menus are added/removed.
    Do you know how I can replace the URL's for a few? (or the ones out of the privileges)

  5. I assumed, as you say, the menu is constructed with ALL the submenus first, and commented all the functions after that, and any other with the word "unset" in them, and the submenus are not rendered. I believe there should be a way to show them WITHOUT adding full capabilities to my subscriber.

    I just got the titles (e.g. "Settings") but nothing inside it.
    Also, I see the url is the element [2] in the submenus. Can I just change the value of the filename.php for each of them in one of the loops of your script to change the link to "#" in all the restricted ones?

  6. @Daniel, @Corey, @Nico : Welcome 🙂
    @sergio: I see you need some help there. Sorry for the late reply though. The core will add full capabilities to any user first and remove them according to your user access level permission. Once the core has finish all their work, our action hook will start acting up. Hence, it is not our control to prevent all the capabilities from adding upfront. [well, you can edit the WordPress core code if you want but our objection is not to touch them right 🙂 ]

    Its been ages since i look at this code.. let's see.. In short you want to remove ALL menu in your WordPress control panel by just adding the value # right? The answer is you can't do that unless you program a function to take account of all the files name available in a panel and remove them via the symbol #. My method above is just providing you a way to remove them by inserting all the file name into an array. Achieving what you want will need to customize the method a bit to meet your need. 🙂

  7. Thanks for the reply.
    I found the way to change the url for all of them. It's the [2] object in the array…
    now, I just must be missing something here.
    You say "…The core will add full capabilities to any user first…" Right?
    But in my case -WP 2.9.1- is not that way.
    In the FIRST pass, the core DOESN'T ADD the ones out of the user's capabilities.
    Was this post for a previous version only?
    Thanks.

  8. yup. Its a code i used on previous version. But this is an action hook so you don't really have to bother about what the core does. Furthermore, in 2.9.1, it seems like there are no changes on wp-admin/menu.php file. Hence, this should work the same as describe in this article.

    "In the FIRST pass, the core DOESN’T ADD the ones out of the user’s capabilities." Please look at wp-admin/menu.php on line 152 – 209 which explain what the core is doing on the menu level.

    Good luck 🙂

Comments are closed.