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 have the WP3.4 and I would like to disable the admin bar. I have tried to do that with many ways, but the admin bar do not display. Is possible to do on this version of WP (3.4) or i make a mistake in the code? Below are the ways that I've tried. Thanks in advance. The 1st :

function my_function_admin_bar(){
            return false;
        }
        add_filter( 'show_admin_bar' , 'my_function_admin_bar');

The 2nd :

add_action( 'init', 'disable_admin_bar', 1 );
function disable_admin_bar() {
    add_filter( 'show_admin_bar', '__return_false' );

The 3rd

    <?php
if (!function_exists('disableAdminBar')) {

    function disableAdminBar(){

    remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); // for the admin page
    remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // for the front end

    function remove_admin_bar_style_backend() {  // css override for the admin page
      echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
    }

    add_filter('admin_head','remove_admin_bar_style_backend');

    function remove_admin_bar_style_frontend() { // css override for the frontend
      echo '<style type="text/css" media="screen">
      html { margin-top: 0px !important; }
      * html body { margin-top: 0px !important; }
      </style>';
    }

    add_filter('wp_head','remove_admin_bar_style_frontend', 99);

  }

}

// add_filter('admin_head','remove_admin_bar_style_backend'); // Original version
add_action('init','disableAdminBar'); // New version


    ?>
share|improve this question
    
AFAIK, it is not possible to "disable" it in the backend, only in the frontend. Your tests do disable it in the frontend, right? –  brasofilo Dec 29 '12 at 18:33
    
The tests do not disable the admin bar backend or frontend. –  MikeD Dec 29 '12 at 18:36

4 Answers 4

up vote 3 down vote accepted

You need to specify the order or number which signifies when the Hook gets fired. In this case I beleive it's 0 and the filter is: wp_admin_bar_render. The action to remove the function I believe is:

remove_action( 'in_admin_header', 'wp_admin_bar_render', 0);

The Function Reference:

Function Reference/remove action

And here it is in the core file:

WordPress Trac.

share|improve this answer
    
Thanks for the help, works, but there’s still a padding at the top of the page. I think that i want to customize with little css code. –  MikeD Dec 29 '12 at 18:51
1  
@MikeD, exactly, just tested and added to an admin_head action: #wpwrap {position: absolute;top: 0px;} –  brasofilo Dec 29 '12 at 18:52

That's a fast and right solution, but does not deactivate all requirements. For example, the scripts and styles are still active and have its load time. A complete solution in a small plugin as follows:

<?php
/**
 * Plugin Name: Remove Admin Bar in WordPress 3.3
 * Plugin URI:  http://wordpress.stackexchange.com/questions/40983/removing-admin-bar-from-wordpress-dashboard
 * Description: Remove Admin Bar
 * Version: 1.0.0
 * Author:      Frank Bültge
 * Author URI:  http://bueltge.de
 * License:     GPLv3
 */

// This file is not called from WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;

add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
    wp_deregister_script( 'admin-bar' );
    wp_deregister_style( 'admin-bar' );
    remove_action( 'init', '_wp_admin_bar_init' );
    remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
    remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
    // maybe also: 'wp_head'
    foreach ( array( 'admin_head' ) as $hook ) {
        add_action(
            $hook,
            create_function(
                '',
                "echo '<style>body.admin-bar #wpcontent, body.admin-bar
#adminmenu { padding-top: 0px !important; }</style>';"
            )
        );
    }
}

also as gist for download and forks.

share|improve this answer
    
Maybe it would be better to put it in 'code' to be visible for everyone. Thanks. –  MikeD Dec 29 '12 at 19:53
    
Frank, I interpreted your original sentences, hopefully I got it right ;) :::: Great script +1 –  brasofilo Dec 29 '12 at 21:21
    
Thanks for edit my answer, is not possible to write good code with a tablet. I miss tags for code, markdown is not useable with tablets. –  bueltge Dec 29 '12 at 22:01

The simple front-end removal is via show_admin_bar():

show_admin_bar( false );

This won't affect admin, because it is considered non-removable there (was not when first introduced, but later changed to that approach). is_admin_bar_showing() is hardcoded to always return true on admin side and there is no "proper" way to remove toolbar there. Which is not to say it can't be done, but that is probably shouldn't be done.

share|improve this answer

I find the solution. functions.php :

require_once('includes/admin/remove_admin_bar.php');

and the php file :

    <?php
        remove_action( 'in_admin_header', 'wp_admin_bar_render', 0);
        echo '<style>body.admin-bar #wpwrap
{padding-top: 0px !important; position:absolute; top: 0px;} </style>';  
    ?> 
share|improve this answer
    
This may work but it's completely wrong... Your echo is printed as the very first thing in the page. Bueltge answer is the best one, IMO. –  brasofilo Dec 29 '12 at 21:24
    
What do you mean with: as the very first thing? i want to disable the admin bar for backend. And for frontend i use : show_admin_bar(false); –  MikeD Dec 29 '12 at 21:33
    
If you do echo '<whatever>'; straight in your functions.php, all your site will printing: <whatever><html><head></head><body></body></html>... I'm not sure Google will like it... –  brasofilo Dec 29 '12 at 21:45
    
I am sorry about that and for this side you have right. Also, after many tests with the echo i realized that the head (html) of my site move slowly down. –  MikeD Dec 29 '12 at 21:53
    
i found many solutions, but first i want to be sure that one of these is the correct solutions. –  MikeD Dec 30 '12 at 10:40

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.