Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I hide/remove the admin bar that is displayed when a user with specific role is logged in? I figured I have to do something with remove_menu(), but not exactly what and how.

Codex

share|improve this question
    
A simple googling can answer you. Why not you tried that first? :) –  Mayeenul Islam Sep 22 '13 at 17:21
3  
Agreed, this is easy to find. But, @Christine's answer is a quality summary. +1 for that... –  Johannes Pille Sep 22 '13 at 17:29

1 Answer 1

up vote 6 down vote accepted

Add the following to your functions.php file as detailed here.

Disable Admin Bar for everyone:

// Disable Admin Bar for everyone
if (!function_exists('disable_admin_bar')) {

    function disable_admin_bar() {

        // for the admin page
        remove_action('admin_footer', 'wp_admin_bar_render', 1000);
        // for the front-end
        remove_action('wp_footer', 'wp_admin_bar_render', 1000);

        // css override for the admin page
        function remove_admin_bar_style_backend() { 
            echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
        }     
        add_filter('admin_head','remove_admin_bar_style_backend');

        // css override for the frontend
        function remove_admin_bar_style_frontend() {
            echo '<style type="text/css" media="screen">
            html { margin-top: 0px !important; }
            * html body { margin-top: 0px !important; }
            </style>';
        }
        add_filter('wp_head','remove_admin_bar_style_frontend', 99);
    }
}
add_action('init','disable_admin_bar');

Disable Admin Bar for everyone but administrators:

// Disable Admin Bar for everyone but administrators
if (!function_exists('disable_admin_bar')) {

    function disable_admin_bar() {

        if (!current_user_can('manage_options')) {

            // for the admin page
            remove_action('admin_footer', 'wp_admin_bar_render', 1000);
            // for the front-end
            remove_action('wp_footer', 'wp_admin_bar_render', 1000);

            // css override for the admin page
            function remove_admin_bar_style_backend() { 
                echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
            }     
            add_filter('admin_head','remove_admin_bar_style_backend');

            // css override for the frontend
            function remove_admin_bar_style_frontend() {
                echo '<style type="text/css" media="screen">
                html { margin-top: 0px !important; }
                * html body { margin-top: 0px !important; }
                </style>';
            }
            add_filter('wp_head','remove_admin_bar_style_frontend', 99);

        }
    }
}
add_action('init','disable_admin_bar');

Disable WP Admin Bar for specific users via user id:

// Disable Admin Bar for specific user
if (!function_exists('disable_admin_bar')) {

    function disable_admin_bar() {

        // we're getting current user ID
        $user = get_current_user_id();

        // and removeing admin bar for user with ID 123
        if ($user == 123) {

            // for the admin page
            remove_action('admin_footer', 'wp_admin_bar_render', 1000);
            // for the front-end
            remove_action('wp_footer', 'wp_admin_bar_render', 1000);

            // css override for the admin page
            function remove_admin_bar_style_backend() { 
                echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
            }     
            add_filter('admin_head','remove_admin_bar_style_backend');

            // css override for the frontend
            function remove_admin_bar_style_frontend() {
                echo '<style type="text/css" media="screen">
                html { margin-top: 0px !important; }
                * html body { margin-top: 0px !important; }
                </style>';
            }
            add_filter('wp_head','remove_admin_bar_style_frontend', 99);

        }
    }
}
add_action('init','disable_admin_bar');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.