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 );

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

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>