News Ticker

How to Disable WordPress Admin Bar for All Users Or Except Administrators

By Ajay Verma - Friday, 13 November 2015 No Comments
Hello Friends, one friend asked me to solve his problem of How to Disable WordPress Admin Bar for All Users Or Except Administrators, without using any plugin.
i am providing code for all possible conditions:
1. Only For A Particular user.
>> Login to Dashboard -> Users -> edit (username) -> Uncheck (Show Toolbar when viewing site)

2. Disable Admin Bar for All Users Except for Administrators
>> Login to Dashboard -> Appearance -> Editor -> choose function.php or theme function.php and,
Paste this code just after php open tag.
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
} }
3. Disable Admin Bar for All Users
If you want to disable it for all users, then simply put use this code.
/* Disable WordPress Admin Bar for all users by unknowndevice64. */
show_admin_bar(false);
4. Use below code if you want only for a certain role
function remove_admin_bar() {
$user = wp_get_current_user();
if (in_array('subscriber', $user->roles)) {
show_admin_bar(false); } }

No Comment to " How to Disable WordPress Admin Bar for All Users Or Except Administrators "