How to disable 3.1 “Admin Bar” via script for the admin user?

You could use a function inside your theme’s functions file to selectively disable it for specific users.

function disable_bar_for_user( $ids ) {

    if( !is_user_logged_in() )
        return;

    global $current_user;

    if( is_numeric( $ids ) )
        $ids = (array) $ids;

    if( !in_array( $current_user->data->ID, $ids ) )
        return;

    add_filter( 'show_admin_bar', '__return_false', 9 );
}

Then call it for the user or users you want to disable the bar for..

Single user:

disable_bar_for_user(1);

Multiple users:

disable_bar_for_user(array(1,2,3));

If you want to just turn it off altogether, then the following should do it(instead of the function).

add_filter( 'show_admin_bar', '__return_false', 9 );

Hope that helps.. 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)