For a while now I have been using some simple code to remove the dashboard menus in WordPress, primarily so that clients can’t change certain settings and ‘break’ their sites. However the code I was using also removed those items for me too. This meant I had to memorise the admin URLs and visit them manually which is not ideal. Today I have managed to solve this problem by hiding WordPress dashboard menus for all except specified users.
The trick is to wrap your code around an if statement that first checks who the user is. The code I am using is below:
Basically the code grabs the current users user ID and then compares it to a list of allowed users. If is matches the function returns nothing, if it doesn’t match then it removes the specified menus in the WordPress admin areas.
In this example users with the ID 1 and 2 can see all menus, however the WordPress links menu will be removed for all other users. It is important to note that this code only removes the menus from view and doesn’t stop users from actually viewing these pages. If they know the URLs they will still load.