Change admin bar to default:off

While I quite like the admin bar I actually want it to be OFF by default instead of ON ( I don’t want to disable it altogether because I want users to be able to turn it on if they want – but but I don’t want to have to manually turn it off for every user ) Is there a way to implement this.

Related posts

Leave a Reply

3 comments

  1. add_action("user_register", "set_user_admin_bar_false_by_default", 10, 1);
    function set_user_admin_bar_false_by_default($user_id) {
        update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
        update_user_meta( $user_id, 'show_admin_bar_admin', 'false' );
    }
    

    Place in theme functions file or you can make into a plugin.

    Once user registers it will go and set the users admin bar prefs to false. The user can then, once logged in, set this to true.

  2. function wpse29210_admin_bar_toogle()
    {
        add_filter( 'show_admin_bar', '__return_false' );
    
        $user = get_userdata( $GLOBALS['current_user'] )->data->ID;
    
        if ( ! is_admin() && $user->show_admin_bar_front )
            add_filter( 'show_admin_bar', '__return_true' );
    
        if ( is_admin() && $user->show_admin_bar_admin )
            add_filter( 'show_admin_bar', '__return_true' );
    
        return;
    }
    add_action( 'init', 'wpse29210_admin_bar_toogle' );