Home  »  WordPress  »  Show or Hide WordPress Admin Bar Plugin

by 1 comment

WordPress No Admin BarThe Admin Bar in WordPress is always shown when in the backend administration area no matter what.

You are given the option to show/hide the admin bar when viewing the site, but there is no option to show/hide the admin bar when using the backend... So I created a plugin to provide that option on profile pages.

Why hide the admin bar in backend?
Normally I like the admin-bar and usually have it enabled, but it's nice to be able to switch it on/off from the "Edit Profile" page. The biggest reason for not loading/showing the admin_bar in the backend is SPEED. Here are 2 instances where I hide it-

    · Sites with many authors/admins
    · Moderating Comments on a Mobile Phone

I occasionally enjoy moderating blog comments using my Android mobile phone and a browser like Opera or Dolphin.... hiding the admin_bar improves Load Speed, Page Rendering Speed, and Scroll Speed. Basically everything.

The wp-admin-bar causes additional CSS, JavaScript, and HTML to be added to every page, increasing request size and time of every request! The jQuery used for the admin_bar keeps it floating at the top using javascript, meaning it gets executed on resize/scroll/load - MAJOR PAIN!

Plugin for Hiding/Showing the WP AdminBar

WordPress with Admin Bar

This plugin provides the option of hiding the admin bar when in_admin. It not only hides the admin_bar, it actually prevents the admin_bar class from even loading, at least in WP version 3.4-beta2-20509 thanks to the wp_admin_bar_class filter.

Follow the Installation steps below and/or read on to see how it works.. it's an incredibly simple plugin and easy to extend for other purposes.

Installation Steps

  1. Download the plugin file: askapache-adminbar-prefs.txt
  2. Save to /wp-content/plugins/askapache-adminbar-prefs/askapache-adminbar-prefs.php
  3. Enable/Disable the plugin from the Plugins Page
  4. Show/Hide admin_bar from the 'Edit Profile' Page

Add Checkbox Option to Profile Page

function askapache_adminbar_personal_options( $profileuser )
 global $wpdb, $wp_query;
 $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $profileuser->ID );
<tr class="show-admin-bar-backend">
<th scope="row">Toolbar2</th>
<td><fieldset><legend class="screen-reader-text"><span>Toolbar2</span></legend>
<label for="admin_bar_backend">
<input name="admin_bar_backend" type="checkbox" id="admin_bar_backend" value="1"<?php checked( _get_admin_bar_pref( 'backend', $profileuser->ID ) ); ?> />
Show Toolbar when in backend</label><br />
add_action( 'personal_options', 'askapache_adminbar_personal_options', 10, 1 );

Save preference when a profile updated

function askapache_adminbar_handle_post($useridtoedit)
 global $wpdb, $wp_query, $current_user;
 $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $useridtoedit );
 if ( !current_user_can('edit_user', $userID) ) wp_die(__('You do not have permission to edit this user.'));
 $show_admin_bar_backend=(isset( $_POST['admin_bar_backend'] ) ? 'true' : 'false');
 update_user_option($userID, "show_admin_bar_backend", $show_admin_bar_backend);
add_action( 'personal_options_update', 'askapache_adminbar_handle_post', 10, 1);
add_action( 'edit_user_profile_update', 'askapache_adminbar_handle_post', 10, 1);

Remove admin_bar from backend

Now we need to hook into init to either show/hide the admin_bar while in the backend (in_admin()) based on the users preference.

  1. Fetches the users preference for showing the admin_bar in the backend
  2. Removes the wp_admin_bar class from even loading (wp_admin_bar_class filter)
  3. Returns false to the show_admin_bar filter
  4. Overrules the admin-bar css applied to the body
function askapache_adminbar_personal_options_init()
 global $wpdb, $wp_query, $current_user;
 $show_admin_bar_backend=_get_admin_bar_pref( 'backend', $current_user->ID );
 if(!$show_admin_bar_backend && is_admin())
  add_filter('wp_admin_bar_class', create_function('', 'return "none".rand(1000,666666);'), 9999999);
  add_filter('show_admin_bar', create_function('', 'return false;'), 999999);
  add_action('admin_head', create_function('', 'echo '<style type="text/css">body.admin-bar {padding-top:0 !important;}</style>';'));
add_action( 'init', 'askapache_adminbar_personal_options_init',0);

Add to Core WordPress

I'm sure this will be added to the dev version of WordPress by someone (volunteers?) and eventually integrated into stable. Note this was built and used on WordPress 3.4-beta2-20509.


April 19th, 2012

Comments Welcome

  • Sergey Oganesyan

    I prefer not to hide. Thanks for the article.

Popular Articles
My Online Tools

Related Articles
Newest Posts

  • @askapache · Jul 21
    Magic spells for sending thoughts across time? Books
  • @askapache · Jul 20
    TV is just a relic of the previous generation. We just don't know it yet.
  • @askapache · Jul 20
    I will never go back on my ideals, no matter the cost. I'll never let the economic vultures steal my dreams. I'd rather give up the ghost
  • @askapache · Jul 18
    I don't want a better seat, I want control of the engine
  • @askapache · Jul 14
    No matter how good u r, there will always be someone 2x, 5x, 100x better. This is true for me and everyone. No direction but forward.
  • @askapache · Jul 12
    Heads up, I'll DDoS the f out of askapache next week, to see how resilient it really is :) - will try to overflow disk, net, and ip stack
  • RUN GCC! This is a typical shirt I wear, from the  shop. A clerk at the LQ recognized it! 
  • Merlin the Magician 
  • ROGUE CODE - Latest novel from @markrussinovich 
  • RTFM - surprisingly very helpful and way more comprehensive than it looks! @redteamfieldman #pwnAllTheThings 
  • Dear Hacker - Letters to the Editor of 2600, from Emmanuel Goldstein 
  • The Mythical Man-Month - Essays on Software Engineering, by Frederick P. Brooks, Jr. 
  • "where wizards stay up late" - The Origins of the Internet. Favorite book detailing the birth of the net and IMPs 
  • ZERO DAY - read before Trojan horse 
  • Trojan Horse, a novel! 
  • The Hacker Playbook - very nice high level overview of attacks 
  • Clean Code - A Handbook of Agile Software Craftsmanship 
  • Secrets of the JavaScript Ninja - By my absolute favorite JS hacker John Resig! 
  • Hacking Exposed 7: Network Security Secrets & SolutionsMy all time favorite, basic but thorough and accurate. 
  • Empty words will be no surrogate for cold resolve. Pain is nothing. 

Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman


It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+ | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain