1

To hide admin bar in front end, we put code in functions.php

//hide admin bar

    add_filter('show_admin_bar', '__return_false');

//or hook action

    function remove_admin_bar() {
            show_admin_bar( false );
    }
    add_action('after_setup_theme','remove_admin_bar');

but how to disable or customize admin bar (wpadminbar) in back-end.

1 Answer 1

2

To disable (or in the case which I show below with code, hiding) the adminbar in the back-end you could use following code snippet.

Please always backup functions.php before editing/adding code.

I added also a capability so the adminbar is still visible for the admin.
(which you can remove if wish by removing !current_user_can( 'manage_options' ) && or whatever you want to do with it (look here for other roles/capabilities, to understand all a little more) )

/**
 * Hide the Toolbar(adminbar) in the back-end using CSS
 * 
 * @version WP 4.8
 * Read more {@link https://codex.wordpress.org/Roles_and_Capabilities#Capabilities}
 *           {@link https://codex.wordpress.org/Function_Reference/is_admin}
 *           {@link https://codex.wordpress.org/Function_Reference/current_user_can}
 */
if ( !current_user_can( 'manage_options' ) && is_admin() )
{
    function wpse271937_hide_adminbar()
    {
        ?>
        <style>
            #wpadminbar {
                display: none;
            }
            #wpwrap {
                top: -30px;/** change to own preference */
            } 
        </style>
        <?php
    }
    add_action('admin_head', 'wpse271937_hide_adminbar'); 
}

To customize the adminbar I leave that to your own preferences, but you can for sure take a look here or maybe in the Codex itself.

Take also a look at these:

I hope this helps you on your way.

Note: the Screen Options and Help tab are with the function as shown above still visible which imho is important. Of course is it also possible to hide/remove them with a (seperate) function.

3
  • Thank you! It's working when hiding it with css code..Generatewp.com is the good page for rendering code automatically.
    – Rei
    Commented Jul 1, 2017 at 6:22
  • @Rei, would be nice to see the answer be accepted so this topic can be closed.
    – Charles
    Commented Jul 3, 2017 at 17:16
  • Yes. It's solved
    – Rei
    Commented Jul 4, 2017 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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