Discover in this tutorial how to remove menu items from the WordPress desktop for other users using code.
As a fan of minimalism, I recommend you to remove all the elements that you are not going to use from Genesis and WordPress child themes.
This is especially useful for your customers, because you’ll avoid them “noise” and favor them to have at hand only what they really need to modify.
While you can somewhat decide which WordPress menu items are displayed depending on the user role, the control it allows you isn’t too granular.
Do you want to get it more fine-grained? Read on:
Snippet to hide items from WordPress Desktop Menu
Add the following code snippet to your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this snippet, you select the menus you want to hide inside the $restricted variable so that they are not accessible.
In the example above, these are the Desktop, Appearance, Tools, Settings and Plugins menus, but you can modify this to suit your needs.
Here are all WordPress Dashboard menu items:
- Dashboard
- Posts
- Media
- Links
- Pages
- Comments
- Appearance
- Plugins
- Users
- Tools
- Settings
As you can see, at the beginning of the function you place a conditional so that this restriction doesn’t affect your user and so that you can access all the menu items.
In the code block, your user is identified by ID=1.
If that’s not your ID, change it!
If you don’t know how to get the ID you can take a look at the tutorial on how to display the user ID in the WordPress admin.
On the other hand, if you later decide that you want to give other users access to a particular menu item, just delete the corresponding line from the snippet (by removing it from the $restricted variable) and access will be available again.
Conclusions
Do you want to hide WordPress admin menu items from other users? Now you know how to do it with a simple block of code.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂