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

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.

Step 1: Add a Custom CSS Stylesheet to your Admin Area

Open up your functions.php file and paste in the following code:

// custom admin style sheet
function my_admin_head() {
echo '<link href="'.get_stylesheet_directory_uri().'/wp-admin.css" rel="stylesheet" type="text/css">';
add_action('admin_head', 'my_admin_head');

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:

#dashboard_right_now, #dashboard_recent_comments, #dashboard_quick_press, #dashboard_primary, #dashboard_secondary, #menu-links, #menu-pages, #menu-comments, #menu-tools, #wp-admin-bar-new-content, #wp-admin-bar-comments, #menu-appearance, #menu-plugins, #menu-settings, #dashboard_plugins, #categorydiv, #tagsdiv-post_tag, #postimagediv {display:none;}

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.

screenshot of a WP Admin interface as per this tutorial
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).

// custom admin style sheet
function my_admin_head() {
$whodat = get_current_user_id();
if ($whodat != 1) {
echo '<link href="/wp-content/themes/makeshop/wp-admin.css" rel="stylesheet" type="text/css">';
add_action('admin_head', 'my_admin_head');

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.


Up Next: How to Include a WordPress Page on Another WP Page or Part of Your Theme (without using a Plugin)