Get $500+ of the best After Effects files, video templates and music for only $20!
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.

Add Comment

Discussion 28 Comments

  1. nathaniel says:

    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.

  2. Rob says:

    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 says:

      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.

  3. 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 says:

      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).

  4. Hemanth G says:

    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?

  5. JPry says:

    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 says:

      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.

  6. FelixFett says:

    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.

  7. Dario says:

    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.

  8. Mahabub says:

    thanks for share this code.

  9. 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

  10. Mohamed Ali says:

    Nice tutorial. Thanks for sharing

  11. @ommunist says:

    Thank you, that worked.

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

  13. Lee Rickler says:

    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/

  14. Jeff says:

    Thanks, this worked out great for me!
    -Jeff

  15. AntoxaGray says:

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

  16. I’ve also tried:

    show_admin_bar(false);

    and it worked … thanks guys :)

  17. nuarharuha says:

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

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.