How to Disable the Admin Bar in WordPress 3.3

How to Disable the Admin Bar in WordPress 3.3

Tutorial Details
  • Program: WordPress
  • Version: 3.3
  • Difficulty: Easy
  • Estimated Completion Time: 15 Minutes

WordPress (Sonny) version 3.3 was just released last night. Half asleep, I downloaded the new version, set up my database, and installed it. Fancy new welcome, I like it. Then, I went and configured my settings just the way I like it. Fix the tagline, set the permalinks (Look, %postname%, awesome, awesome to the max), set the date and time format, etc. etc. Then I disabled the admin-bar. Clicked “Update Profile”. Great! Hey, wait a minute. The admin-bar is still there!? What the [Insert Expletive]!


Why Can’t I Get Rid of The Admin Bar?

With the new WordPress version, the WordPress core developers decided that the admin bar is an essential part of the Admin section (from what I understand). Personal, I don’t find much use for it. To me it’s just a ugly bar at the top of the page with only some of the options found on the side-menu. Not, that I have an intolerable hate of the admin-bar. I just don’t like it.

With the previous versions of WordPress you could just go to the user profile to disable the admin-bar, or you could use this popular code in the functions.php file.

add_filter('show_admin_bar', '__return_false');

With the release of version 3.3 we no longer are given the option to disable the admin-bar in the Admin section. I applaud the Core WordPress Development Team for trying to make WordPress easier to use and more accessible, but they seem to be missing something in their thinking. People like to have options, and they don’t like it when those options are taken away. Especially when they’ve utilized those options.

So, I quickly came up with this solution to disable the admin-bar.


Disabling the admin-bar in the Admin Section

This code is going to be placed in the functions.php file, so go ahead and open it up in your favorite text editor.

First let’s set up the function with a check.


if (!function_exists('disableAdminBar')) {

	function disableAdminBar(){
  
  }

}

This is going to make sure that the function ‘disableAdminBar’ doesn’t already exists. If it doesn’t the our function will run.

Next, let’s remove the action that will enables the admin-bar.


if (!function_exists('disableAdminBar')) {

	function disableAdminBar(){
  
  	remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
  
  }

}

Now, for the action hook that initializes the disableAdminBar function.


if (!function_exists('disableAdminBar')) {

	function disableAdminBar(){
  
  	remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
  
  }

}

add_filter('admin_head','remove_admin_bar_style_backend');

OK, that disabled the admin-bar, but there’s still a 28px padding at the top of the page.

28 px Padding

You can go into the admin-bar.css file and edit the css there to remove the padding. The css property you want to edit is this.

body.admin-bar #wpcontent,
body.admin-bar #adminmenu{
padding-top:28px;
}

You could dig through the wp-admin.css file and change the css there, but I think it’s better to preserve the core files. So, I’m going to override the css in the function we just made. This is the function we’re going to use to override the css.

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

Here is the whole function to disable the admin-bar and overriding the css all together.


if (!function_exists('disableAdminBar')) {

	function disableAdminBar(){
  
  	remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
  
    function remove_admin_bar_style_backend() { 
      echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
    }
          
    add_filter('admin_head','remove_admin_bar_style_backend');
  
  }

}

add_filter('admin_head','remove_admin_bar_style_backend');

Now that 28px padding should be gone.

No Padding

It’s not pretty but it works, also by overwriting the css this way. If you ever want to re-enable the admin-bar. You won’t have to change the core css back.


Disabling the admin-bar in the Admin Section

If you want to disable the admin bar of the frontend of your site, you can go into your user profile and uncheck “Show Toolbar when viewing site“. Easy enough, but if you want to disable the admin-bar all together, we’re going to have to add some more to the ‘disableAdminBar’ function.

Here’s the action to disable the admin-bar on the frontend.

	remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );

In our ‘disableAdminBar’ function. It looks like this.


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() { 
      echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
    }
          
    add_filter('admin_head','remove_admin_bar_style_backend');
    
	}

}

add_filter('admin_head','remove_admin_bar_style_backend');

The admin-bar is gone, but one problem. Now, there’s a 28px margin on the top of your site.

28px Margin

This one is tricky. This css is hard coded in the <head> when the “Show Toolbar when viewing site” is checked. I haven’t been able to figure out how to remove the css, so we’re going to have to override it like with the admin section using this function.

function remove_admin_bar_style_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);

The 99 at the end of the add_filter hook, is to ensure that the css is in the <head> comes after the original hard coded css in the <head>

No Margin

Here’s our completed function.


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


Conclusion

This may not be the most eloquent solution, but it works as a quick fix for now. I can’t wait to see what other solutions and WordPress hacks that are to come.

Well, WordPress version 3.3( a.k.a. Sonny) is finally here. If you haven’t upgraded yet, get to it.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • nathaniel

    hey jason thanks for the tut. i tried your code and it wasn’t working because of the last line add_filter(‘admin_head’,'remove_admin_bar_style_backend’); . I replaced it with add_action(‘init’,'disableAdminBar’); , and it worked. I found the answer here http://wordpress.org/support/topic/cannot-remove-admin-bar-from-wp-admin-in-33, in a comment by gilgimech.

    • Brandon Jones

      Thanks for the add Nathaniel! I’ll update the code ;)

    • Jason Witt

      Ha, that’s funny I’m gilgimech. I was going to send in an update to this tut before it got published, but I didn’t get it in time. I also have this in plugin form that also restores the admin head like in WP 3.2. http://wordpress.org/extend/plugins/old-skool-admin-head/

  • http://vermeertech.nl Rob

    If you use show_admin_bar( false ); then you don’t have to use inline styles for the front-end (which is ugly).

    • Jason Witt

      Well, I was was still getting the the margin with the show_admin_bar( false ) method. Maybe it was the theme I was using. Unchecking “Show Toolbar when viewing site“ is actually the best option, if you can use it.

  • http://line-in.co.uk Simon Fairbairn

    It’s interesting that you say “[p]eople like to have options” on the same day that Andrew Nacin (core developer) posted this:

    One of the tenets of the WordPress philosophy is Decisions, Not Options … WordPress is known for its simplicity and usability, but I can still think of a half-dozen options I wouldn’t hesitate to remove under the right circumstances. Many WordPress plugins subject their users to too many options.

    Not saying it’s right or wrong either way, just that it might explain why they’ve made the Toolbar a more permanent feature.

    • Brandon Jones

      Good point Simon… options are always going to be a double edged sword with WordPress (or any UI design for that matter – consider even something as simple as the Kindle Fire vs. the iPad 2 in terms of the physical design). For me, I like knowing that I have options if I really want them, but that I’m not required to make a decision on them until it’s really necessary. That’s where little mods like this can be quite useful – they’re there, documented and ready to go if I ever need them – but WP is just fine for the time being :) (although I will say that removing the admin bar was the first thing I did in 3.2, I just don’t mind it as much in 3.3).

  • Hemanth G

    Hi! Jason,

    Thankyou for the TUT, Was looking for a fix since I upgraded to ‘Sonny’. But wanted to know does this fix also remove all the user options which are available on the right side of the Admin Bar? Where users can access their profile and also Log Out from the site, is there a way to keep only that part of the toolbar enabled?

  • JPry

    Be aware that while you can use this method to disable the Toolbar in 3.3, this definitely qualifies as a hack and you are also removing functionality. Where do you now go to log out? What about the Network Admin screen for Multisite?

    You do have a point about the Toolbar not really having much useful functionality to it, but I see this as an advantage. Why? Because now, as a developer, you have that much more room to put in the stuff that YOU want without having to do as much removal of Core stuff to make room. There’s a very nice explanation by Core Developer Andrew Nacin that explains what you can do to add your own items to the Toolbar: http://wpdevel.wordpress.com/2011/12/07/admin-bar-api-changes-in-3-3/.

    Obviously, anyone can run their own site how they see fit. But I would encourage you to see how you can make the most of the Admin Toolbar, rather than looking for how you can simply get rid of it.

    • Jason Witt

      It all depends on how you use it. For instance, the new Toolbar covers up the first few lines of php errors. When you developing a theme or plugin those errors are essential for debugging. You can put this in your functions.php file developing purposes and take it out for a live site. It’s just an option.

  • FelixFett

    Most simply way – go to Your profile page in admin section of Your wordpress site and un-check options:
    “show bar ….”
    in admin section it will show 28px empty space but only there in the simplest way You can enable/disable adminbar for each : front & administration area.

    • http://www.fahdmurtaza.com Fahd Murtaza

      It doesn’t work for admin side, just for front end. Thats why this tutorial.

  • Pingback: WordPress 3.3 Admin Bar verschlanken oder deaktivieren » t3n News

  • Dario

    Today I’ve opened my functions.php file on my new WP 3.3 installation and wrote:

    show_admin_bar(false);

    the admin bar disappeared.

    • Marco

      Dario, do this action disable the toolbar only on frontend?

      Me, I need to disable ONLY the frontend toolbar. What do I have to do?

      • Dario

        >Me, I need to disable ONLY the frontend toolbar. What do I have to do?

        Use the code I posted, it should works. If it doesn’t work just delete it.

        • http://keeblesmith.com Chris Keeble

          I can confirm Dario’s method does work to remove the admin bar from the front-end (but not from the dashboard / backend). Tested on wordpress-3.4.2

    • http://www.mauriciocastillo.com Andrés

      Soooo simple, tks =)

    • mnowluck

      hehe, this removes it from the frontend, and this is just what I need

    • http://www.mediafirerepack.net/ Vikas Kapadiya

      thanks you very much .. it is worked .. tested on 3.4.2

  • Pingback: WordPress 3.3: Hot or Not?

  • Pingback: WordPress 3.3: Hot or Not? | SNS Online

  • Pingback: Disable the Admin Bar in WordPress 3.3 | Developers Site

  • http://liveonlineradio.net Mahabub

    thanks for share this code.

  • http://www.fahdmurtaza.com Fahad Murtaza

    This tutorial inspired me to write this plugin where each user can select the admin toolbar settings within admin panel. Can be useful as a plug and play thing rather than changing functions.php. I just submitted to the wordpress repository. Here is the link on my site

    http://www.fahdmurtaza.com/wordpress/plugins/hide-toolbar

  • http://jabanalab.com Mohamed Ali

    Nice tutorial. Thanks for sharing

  • http://ommunist.com @ommunist

    Thank you, that worked.

  • Pingback: Cómo editar la nueva barra de herramientas en WordPress 3.3 y personalizar el menú

  • Pingback: Как отключить Панель Администратора в WordPress 3.3 | Wordpresso

  • http://www.magentodevelopmentindia.in/ Daniel Watson

    Really great post. As i used the code and got the solutions .
    Thanks for sharing such a useful stuff.

  • Pingback: Remove Admin Bar in Wordpress 3.3 | wpBite.com

  • http://pointandstare.com Lee Rickler

    And if you can’t get to grips with all this ‘coding’ try using this plugin:
    http://wordpress.org/extend/plugins/point-and-stare-cms-functions/

  • Jeff

    Thanks, this worked out great for me!
    -Jeff

  • http://www.youtube.com/user/izvarzone AntoxaGray

    add_filter(‘show_admin_bar’, ‘__return_false’); actually works in 3.3.1

    • http://www.facebook.com/debbie.salemink Debbie Salemink

      thanks, it does! without adding core files which is better avoided..but it shouldnt be that difficult not everyone wants the adminbar on their site or to spent time researching how to get rid of it. We’re not a blog anymore, we’re building cms sites on the best blogging system :)

  • http://shibulijack.wordpress.com Shibu Lijack

    The following plugin works perfect up to 3.3.1:
    http://wordpress.org/extend/plugins/cj-remove-wp-toolbar/

  • http://www.kreativtheme.com Kreativ Theme

    I’ve also tried:

    show_admin_bar(false);

    and it worked … thanks guys :)

  • http://www.google.com nuarharuha

    Hi, thanks for the tips, for 3.3.1, the following work for me
    remove_action(‘init’,'_wp_admin_bar_init’);

  • http://bevisible.dk Dannie

    Wow, Thank Shibu!
    Plugin is working great :) Perfect for code-noobs like me.

  • http://www.triwidibalitour.com sariyantamade700

    Thank you for for this great tutorial, I don’t know what to say to make this comment valid:D
    Simple but useful
    Again, Thank You

  • nd

    I found this page while looking for a way to disable the admin bar.

    Removing this option was a mistake…compounded by the fact that (as of 3.4.1) the option to disable it is still available on the Profiles page…. which literally leads the user into “user error mode” — what am I doing wrong…. I guess I better search….. oh, isn’t that nice… they made a half-assed change half-assedly.

    .

  • Chief

    You’ve really helped me out! :D

  • http://www.serene-falcon.com Claverhouse

    Speaking as one who has tried in vain — were I a coder I would try myself — to find a Greasemonkey/Stylish/Whatever script to remove those nasty little toolbars from sites on the hosted platforms such as WP.com & Blogger, I can’t help wondering if the imposition of the Toolbar was connected to the influx of Microsoft users whem WP.com took in the defunct Windows Live Spaces bloggers. Who would then go on to use the software on their own hosted blogs as they went on from WP.com

    They are naturally the toolbar manufacturers’ best friends, as anyone may see on inspecting a Windows user’s desktop, and the sort of people who use Microsoft feel lost and unhappy without the familiar aid of such weird objects; thus the way was forward, combined with the natural disdain of devs for their users — ‘Decisions, Not Options’ — to introduce this particular Idiot’s Delight and then, spreading conformity and blandness across the web, to make it compulsory.

    The only benefit may be that all the other toolbar installers can join together and WP can monetize this toolbar by combining with them into creating a mandatory gigantic toolbar adding Ask, Yahoo, FB, Google+, Bing, Alexa, Conduit and every other crapbar maker, that will take up 2/3 of the screen and float down so that it is always in view. With flashing adverts.

  • http://kyro.com.pt/site André Bernardes

    Is this code working for 3.4.1? I’ve tried it and the admin bar is still presente :(

  • Adam Šír

    Hello everybody,

    I have easier solution without gliching in php.

    Just put this code to colors-fresh.css located in wp-admin/css folder

    #wpadminbar {display:none;}
    #wpcontent,ul#adminmenu{position:absolute;top:-28px;}

    … and adminbar will be disabled.

  • http://www.video-tutorial.org David Lambert
  • abiodun

    someone should please show me how to remove COMMENT CLOSED in version 3.3.1, i have tried to go and disable it and i have removed the <php comment….. stuff under the page.php
    But the COMMENT CLOSED still visible

  • Pingback: An Unobtrusive ‘Edit’ Link | Darren Hoyt Dot Com

  • http://nottalotta.com Adam

    Thanks for the tut. I was looking for a simple way to remove the admin bar and it worked great.

  • http://1up-dnb.com Kirt Rainford

    Just to say, this is very easily accomplished with a simple PHP trick on any WP version. All you need to do is replace the wp_head(); in your theme with this code:

    ob_start();
    wp_head();
    $headout = ob_get_contents();
    $headout = str_replace(“”, “”, $headout);
    $headout = str_replace(‘margin-top: 28px’, “margin-top: 0px”, $headout);
    ob_end_clean();
    echo $headout;

    And just tailor it to suit your own needs.
    Peace.

  • http://www.eawebagency.com Ariel

    Hi, adding this … add_filter(‘show_admin_bar’, ‘__return_false’); … to functions.php works for me, I am using version 3.3.2 thank you !

  • Rob Teed

    OK, I have disabled the tool bar. Looks great! However, now I need to place a”User Profile” link on my homepage menu. I’m very new with this stuff so I might not be phrasing things right. You can see my site at gravedata.com

  • Joshua

    Just used this simple, and very effective walkthrough in 3.5 removing the two lines pertaining to the admin dashboard resulting in full functionality for admins logged in and using the dashboard while hiding the toolbar from ALL other users.

    Great tut – thanks!

  • hob

    hi, all you need to do is edit these 2 php files in wp-includes, and edit the css in admin as stated above.
    changes

    class-wp-admin-bar.php
    final protected function _render( $root ) {

    to…

    final protected function _render( $root ) {
    return;

    and

    admin-bar.php
    function _admin_bar_bump_cb() { ?>

    to…

    function _admin_bar_bump_cb() { return;?>

    thats it.
    good luck,
    hob

    • Rudd

      It’s NOT a good idea to edit the core file. You’ll lose those changes when update to latest version of WP

  • http://www.facebook.com/profile.php?id=736140231 Rasha Nour Eldin

    why its not working with 3.5 ???
    Thanks

  • Pingback: WP – Disable Admin Bar