Disable the admin bar for all users except admin

南楼画角 提交于 2019-12-19 11:48:13

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/8194649/disable-the-admin-bar-for-all-users-except-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!