Disable toolbar for Users

This script disables the WordPress toolbar for all users except admin.  In order to set this for other user roles, change line 5 to your liking.

Add to functions.php file or plugin.

// disable the toolbar except for admin
add_action('init', 'remove_admin_bar');

function remove_admin_bar() {
	if (is_user_logged_in() && !current_user_can('administrator') && !is_admin()) {
	  add_filter( 'show_admin_bar', '__return_false' );
	  remove_action( 'personal_options', '_admin_bar_preferences' );

	  echo '<style type="text/css">
	  	#wpadminbar {
	  		position:relative;
	  		display:none;
	  	}
	  	body {
	  		margin-top:-28px !important;
	  	}
	  </style>';
	}
}

 

Dave Winter focuses in WordPress UI Design and WordPress Plugin Development (some have labelled him a fanatic) but has hands in many other projects, including photography and music. He's never far from a computer... or an iPad (for testing purposes, of course). If you've been to a WordCamp in Southern California, he probably already knows who you are (or maybe not - he's terrible with names). Dave currently teaches courses at California State University, Long Beach alongside his small business at dauid.us (and his students think he's pretty boss).
© 2008-2020, dauid.us