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.

I am using the following code to remove the admin bar (client request).

add_filter( 'show_admin_bar', '__return_false' );

Trouble is, it leaves some autogenerating CSS, which places a massive white line at the top of my page in its place (via a 28px top margin rule). How can I turn this off as well?

share|improve this question
    
You could use jQuery to control the css, i guess –  Xavier Apr 4 '11 at 10:54
2  
57% is a very low accept rate - can you go back and follow up some of your questions? –  anu Apr 4 '11 at 11:10
    
I'm echoing @anu, please go back and review your questions and please reward the people who took the time to give you an answer by accepting the best answer and up-voting any helpful answers. See paragraphs 3 & 4 after the header "How do I ask a Question" –  MikeSchinkel Apr 5 '11 at 5:34
1  
Could you trace where exactly extra CSS comes from? What file or script? From looking over code that __return_false snippet should kill all CSS and JS that admin bar uses. –  Rarst Apr 5 '11 at 15:08

4 Answers 4

up vote 2 down vote accepted

To completely remove the Admin bar deregister the js and css using wp_degregister_script and remove the action.

if (!is_admin() && !current_user_can('add_users')){
    wp_deregister_script( 'admin-bar' );
    wp_deregister_style( 'admin-bar' );
    remove_action('wp_footer','wp_admin_bar_render',1000);
}
share|improve this answer
    
The script is part of a toggle in the admin area, so different users can turn it on and off (why is this not default behaviour?). Would I run into problems reinstating the admin bar using this method? –  Mild Fuzz Apr 4 '11 at 12:58
    
Also, strangely, my hack to fix the issue has been to remove the wp_head, am I to assume that the admin bar attaches to the footer? Because my hack (albeit ill advised) works well. –  Mild Fuzz Apr 4 '11 at 12:59
    
The Admin Bar hooks into wp_footer(), rather than into wp_head(). Note: removing either of these hooks is a bad idea. –  Chip Bennett Apr 4 '11 at 16:51
    
I did say that :) –  Mild Fuzz Apr 5 '11 at 8:53
    
This will not show the admin bar, but it will keep the top 28 pixel margin which was the original problem. –  Jan Fabry Apr 8 '11 at 12:46

I think you added this filter too late (on init?), so that the initialization does happen, but the rest does not.

The three places that check show_admin_bar (via is_admin_bar_showing()) are:

Because _wp_admin_bar_init() is called on init, you will be too late if you also add the show_admin_bar filter on init, unless you change the priority.

This will not render the admin bar, but still add the 28px margin:

add_filter( 'init', 'wpse13875_init' );
function wpse13875_init()
{
    add_filter( 'show_admin_bar', '__return_false' );
}

This will completely disable the admin bar, because it will be executed before _wp_admin_bar_init():

add_filter( 'init', 'wpse13875_init', 9 );
function wpse13875_init()
{
    add_filter( 'show_admin_bar', '__return_false' );
}
share|improve this answer
    
This solved it for me. –  supertrue Jun 14 '12 at 21:28

see this answer, was a complete solution including unload the scripts and styles. The hook remove the admin bar, but not the load of js and css.

share|improve this answer

Can't you just override the CSS - probably the easiest way - add a display: none to whatever the admin bar selector is

share|improve this answer
    
The admin bar css is dynamically added to the *html element with javascript. It will override any attempt to override it. –  Chris_O Apr 4 '11 at 11:32

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.