How to Easily Hide Admin Panels in WordPress

Filed August 21st, 2010 under WordPress

The WordPress admin back end can be overwhelming. Combine a default installation with a handful of custom-post types and plugins, and you’ve got yourself 15 or 16 options panels – many of which an end user (i.e. a client) will never use.

It’s easy to forget that this sort of clutter confuses users. That’s why hiding some of these panels can often be a good idea. Luckily, there’s an easy to do that.

The CSS Technique

Every admin panel in the WordPress backend is identified as #menu-title in the HTML formatting. If we want to hide a particular administration panel that’s natively displayed for a particular user class, we just need to declare display:none; as a CSS attribute of the ID.

If we want to hide the Plugins panel from users, we simply add the following to functions.php:

<?php
add_action('admin_head', 'hide_menus');

function hide_menus() {
	global $current_user;
	get_currentuserinfo();

	If($current_user->user_login != 'admin') {
		?>
		<style>
		   #menu-plugins{
		        display:none;
		   }
		</style>
		<?php
	}
}
?>

Let’s break this down.

The function hide_menus queries the user info for the currently logged in user. If the user isn’t an administrator, then the content in the <style> attribute is embedded in the backend. In this case, display:none; is applied to #menu-plugins, and the Plugins panel is hidden from the user’s browser.

Changing which option panel is hidden, or hiding additional panels, is simply a case of modifying which #menu-title is defined in the <style> attribute.

This technique doesn’t disable or modify actual user permissions, but simply modifies the way browsers display the backend. It’s not a secure solution, but it’s not meant to be – it’s just a quick and dirty way of modifying the administrative UI for end users.

Plugin Alternatives

There are a number of plugins that reproduce the CSS technique, without the need to manually edit functions.php.

Hide Admin Panels enjoys fairly robust support for recent versions of WordPress, and is updated regularly.

Credits

Kudos to Brian Williams for his article and source code for this technique.

Joshua Kelly
Director of Human/Machine Synthesis

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>