Reputation: 2619
I'm looking for a programmatically way to hide top toolbar, which displays for logged in users in WordPress.
I tried some things I found on different websites but nothing worked, like :
show_admin_bar(false);
or
add_filter('show_admin_bar', '__return_false');
Please note that I want to remove the toolbar on the front and the back end, including for admins.
Thanks for any advice !
NOTE : I'm using wordpress 4.0
Upvotes: 0
Views: 643
Reputation: 27599
You can use the action hooks wp_before_admin_bar_render
and wp_after_admin_bar_render
to trigger and end capturing the output buffer, which can just be tossed away since you aren't using it. The PHP functions ob_start()
and ob_get_clean()
can be used for this purpose. Note that the CSS on the admin will leave an empty spot where the bar used to be, adjust using custom CSS.
if ( is_admin() ){
add_action( 'wp_before_admin_bar_render', function(){ ob_start(); } );
add_action( 'wp_after_admin_bar_render', function(){ ob_get_clean(); } );
} else {
show_admin_bar( false );
add_filter( 'show_admin_bar', '__return_false' );
}
Upvotes: 1
Reputation: 6412
I would recommend hiding using CSS. You can use the filters to hide the admin bar for regular users, but you would need CSS for admins.
#wpadminbar {
display:none;
}
or
.logged-in #wpadminbar {
display: none;
}
Upvotes: 1