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.
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.
Share Improve this question edited Jul 1, 2017 at 5:12 hwl 2,14510 silver badges15 bronze badges asked Jul 1, 2017 at 2:16 ReiRei 4411 bronze badges1 Answer
Reset to default 2To 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/Roles_and_Capabilities#Capabilities}
* {@link https://codex.wordpress/Function_Reference/is_admin}
* {@link https://codex.wordpress/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:
wp_before_admin_bar_render
admin_head
(plugin page)
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.