Disable the admin bar for all users except admin

2019-02-20 08:23发布

I have installed WordPress and BudyPress. I want to disable the admin bar which appears on the top for all users.

Can somebody tell me how to do that correctly?

2条回答
小情绪 Triste *
2楼-- · 2019-02-20 09:01
function sushil_return_false() {
    global $current_user;

    // return "false" for all users that do not have the "administrator" role
    if( !in_array('administrator',$current_user->roles) ) {
        return false;
    } else {
        return true;
    }
}

add_filter( 'show_admin_bar', 'sushil_return_false' );
查看更多
Deceive 欺骗
3楼-- · 2019-02-20 09:03

In your functions.php file, you can add one of the following code snippets to get the indicated results:

// Only display to administrators

 add_action('after_setup_theme', 'remove_admin_bar');

 function remove_admin_bar() {
     if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
     }
 }
查看更多
登录 后发表回答