WordPress: Show admin bar only to admin users

When you log in to WordPress, you get an admin bar at the top. This admin bar is useful mainly for the blog administrators. If you have multiple authors and contributors for your WordPress website, you might want to hide this admin bar. A simple contributor doesn’t really need the WordPress admin bar. It is also a good idea to remove the admin bar if your website is a membership site.

You can show the WordPress admin bar only to admin users. Simply copy-paste the following code snippet into the theme’s functions.php file. Once saved, only admins will see the admin bar.

if (!current_user_can('manage_options')) {
	add_filter('show_admin_bar', '__return_false');
}

You might want to add a log-in and log-out link on your website otherwise logged-in users will have trouble logging out. You can use the following function to add a log-out URL function in the theme.

echo wp_logout_url( $redirect );