How to Hide Certain Elements of the WordPress Admin from Specific Users

December 7, 2012 10:28am

Sometimes when you’re building a site for a client, you don’t want them to have access to every last element of the WordPress administrative interface. Could be they’re not technically savvy enough to be trusted, or it could simply be that you’re not utilizing Links or Categories, or Tools and Settings are just too much clutter in the interface.

I use this very simple, tried and true method to hide elements in the WP Admin area. Note the use of the word “hide” as this methodology does not prevent them from accessing these areas if they know the URL, or if a link somewhere else in the interface points to them, it simply uses CSS to display:none; certain things.

That adds a link to our soon to be created stylesheet in the current theme, which is only applied to WordPress Administrative area pages, not the front end of your site. This will add it to everyone’s WP Admin, though. We’ll discuss adding stylesheets for specific users later.

Next, we’ll want to create that file, so in your current theme’s directory (ie, /wp-content/themes/YOURTHEME/) create a new file called wp-admin.css.

Step 2: Use the CSS Display Property to Start Hiding Stuff

You’ll need to use your browsers Inspector or View Source to find the IDs of the elements you want to hide and then use display:none; in your new CSS file to hide them. For example, if you want to hide the Links menu item, open up that wp-admin.css file and paste in:

#menu-links {display:none;}

Here’s an example of a stylesheet I created recently to hide loads of things from a user I didn’t think could handle / needed all of the bits and bobs:

That hides various Dashboard panels (since I was going to hide the Pages area and these pointed to Pages or other things I didn’t care to show off in the Dashboard), the Links, Comments, Tools, Pages, Plugins and Settings navigation elements, and the Category and Tag boxes in the Post Editor.

An example of one possible end result

Isn’t there a Better Way to Remove this Stuff?

Yes, there is a better way which involves actually removing a lot of this stuff instead of just hiding it via CSS. I cover how to remove Dashboard widgets, for example, in this post. But there isn’t a way, that I’m aware of, to easily remove things like Posts or Links. Since I’m just hiding this stuff anyway, why not hide everything I want to instead of having two methods of removing something from the admin area?

But then Admins Who Can be Trusted Can’t See This Stuff!

True! Check out the code below which allows you to hide these items from everyone except the main site admin (the one created when the blog is setup, the first user on the blog, who has an ID of 1).

The $whodat checks to see who the current user is, and if it’s the user with an ID of 1, it doesn’t add this stylesheet. You could change it to if ($whodat == 3 || $whodat == 19), for example, if you only wanted to apply the stylesheet to the users with IDs of 3 and 19.

Discussion

Isn’t there a way you could apply it just based on user role? That would be most convenient. As you probably want all admins to see everything, while Editors, Authors, etc, might need to be limited to less….

You certainly could, Tevya, in fact that’s how those roles work right out of the box, except they don’t hide anything via CSS, they actually remove the functionality altogether. You could also just alter the capabilities of specific roles to accomplish this kind of behavior as well.

For my purposes, sometimes I just want to hide some things from particular clients who I know will have a rough time / fiddle & break things.