#16249 closed defect (bug) (worksforme)
Control of admin bar hiding/display
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 3.1 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | justin@…, xoodrew@… |
Description
Can the assignment of space for an admin bar be controlled by the same switch that turns it on and off? At the moment, you can make the bar not appear but space still is set aside for it after ticket #16222. You need to remove the space as well as hiding the bar.
Attachments (2)
Change History (14)
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
comment:2
jtsternberg — 17 months ago
- Cc justin@… added
- Keywords needs-patch added
- Resolution worksforme deleted
- Status changed from closed to reopened
The screenshot displays this error still happening, using both filter's Nacin put above. The code in the head is not being removed:
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
comment:3
jtsternberg — 17 months ago
adding this snippet will take care of it, but not sure that should be necessary.
show_admin_bar(false);
remove_action('wp_head', '_admin_bar_bump_cb');
Seems like it's too late when you call add_filter( 'show_admin_bar', '__return_false' );.
It works for me.
- Resolution set to worksforme
- Status changed from reopened to closed
function ds_hide_toolbar() {
add_filter( 'show_admin_bar', '__return_false' );
}
add_action( 'init', 'ds_hide_toolbar', 1 );
or
add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
comment:6
jtsternberg — 17 months ago
Thank you for your response.. The only thing missing in my code was the "1" at the end of the add_action. With the diff that I just added, that "1" doesn't seem to be needed. Please take a look and consider it?
comment:7
jtsternberg — 17 months ago
And to be as clear as possible, this was my code that was not properly removing the space at the top of the page for the admin bar:
// Hide dashboard, admin bar, etc from subscribers
add_action( 'init', 'aec_hide_admin_stuff' );
function aec_hide_admin_stuff( ) {
if ( !current_user_can('edit_posts') ) {
show_admin_bar(false);
}
}
Btw: If the CSS is printed the JS files will be enqueued too, so your patch doesn't help.
comment:9
jtsternberg — 17 months ago
Good point. I'll see if I can upload a more thorough patch. Thank you.
comment:10
jtsternberg — 17 months ago
- Keywords has-patch added
Ok, I scoured the source code of my page after applying this patch to be sure it was removing everything that
function ds_hide_toolbar() {
add_filter( 'show_admin_bar', '__return_false' );
}
add_action( 'init', 'ds_hide_toolbar', 1 );
was removing, so hopefully this patch is considered for addition?
comment:11
jtsternberg — 17 months ago
- Keywords has-patch removed
Bah, sorry, that diff works too well... the $show_admin_bar global is not set yet, so it removes it from the front-end permanently whether you specify that option or not. I'll have to give it some thought, or just drop it.
comment:12
DrewAPicture — 17 months ago
- Cc xoodrew@… added
Removed comment: It was a theme-induced issue.

You're not disabling it properly. Use the following function or hook:
Or:
Additionally, you can change the callback that spits out the CSS, thus allowing you to adjust it for your theme if for some reason it isn't compatible.