Skip to main content

How to Remove the Admin Bar from WordPress 3.1

You may have noticed that there is a new admin bar add to WordPress 3.1 that shows up when you are logged in as a subscriber or above. While I can see that this might be useful on some sites, for most this is just an annoyance and makes the site look too generically ‘WordPress’ or detracts from existing functionality that you may have added, such as search adaptations.
For example if you have a site that requires people to login before they can make a comment, or login before they can download, this will add to the screen a bunch of ugliness that is totally unwanted. Not to mention a bunch of scripts and codes that will slow the response time of your website.
So with that in mind I have created a bunch of samples that you can add to your functions.phpheader.php if you prefer) to remove this option. (or

For your functions.php

1
2
3
4
5
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);
}

For your header.php

1
2
3
4
5
6
7
if (!current_user_can('add_users')){
 wp_deregister_script( 'admin-bar' );
 wp_deregister_style( 'admin-bar' );
 remove_action('wp_footer','wp_admin_bar_render',1000);
}
?>
Note: place just before in header.php
I’ve only focused on the front-end user experience, rather than both the site and the admin pages.

Code break down….

!is_admin()

!is_admin() checks if this is not an admin page

!current_user_can(‘add_users’)

current_user_can('add_users') checks if the current user can add a user to the WordPress system, this only applies to administrators. So, !current_user_can('add_users') checks if the current user can not add new users, which means all other users. If you want to make the admin bar available to your authors and above then change ‘add_users‘ to ‘publish_posts‘. For a full list of capabilities check out this page on the WordPress Codex.
Do remember that roles and capabilities only apply to logged in users. If you don’t want to see the bar even as an administrator, then remove it from the if statement, or if you are doing this in the header.php remove the if statement all together, leaving it’s contents behind.

wp_deregister_script( ‘admin-bar’ );

wp_deregister_script( 'admin-bar' ); removes the Javascripts that are loaded for the admin bar.

wp_deregister_style( ‘admin-bar’ );

wp_deregister_style( 'admin-bar' ); removes the CSS file from being loaded for the admin bar, as we don’t need to style it.

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

remove_action('wp_footer','wp_admin_bar_render',1000); tells the system not to render the admin bar menu (html) when wp_footer is called, the value 1000 means run it after any other wp_footer action that has a lower value, the default is 10.

Want a plugin to do this?

There are a few plugins available to do this for you, BUT they will not be as efficient (read “will slow down your WordPress install silghtly more”) as putting this code directly into your header.php which is the most efficient placement as it only loads for front end pages, or in to your functions.php file which is the given standard. However, here are a list of plugins to do the job if your not confident with playing with php codes:
Admin Bar Disabler →
Custom Admin Bar →
Global Hide/Remove Admin Bar Plugin →
Admin Bar Removal →

Update with cleaner code

thanks to the lovely people at WPUA (WordPress Users Association) I’ve been given an even cleaner bit of code to replace the de-register script and styles and to get rid of the remove_action
1
add_filter( 'show_admin_bar', '__return_false' );
Of course you can still do all the same !is_admin or !current_user_can stuff if you like

Comments

Popular posts from this blog

Titanic The most famous incident in history Women Jobs STC (48498)

Titanic The most famous incident in history in the North Atlantic on April 15, 1912 Belfast is frequently alluded to as " Titanic Town " and there are awesome purposes behind that. No place else on the planet can guarantee a superior relationship with the most popular ship at any point made. It was structured, built and developed in the Belfast shipyard and made its first journey on April 10, 1912. Around then she was hailed as the new miracle of the world and few individuals at that point recognized what lay in front of her. The Titanic was a fabulous blend of Edwardian plan, craftsmanship, and designing.  Belfast during 1909 was one of the world's most noteworthy ports and Harland and Wolff were known as extraordinary compared to other ship manufacturers all through the world. They had a profoundly talented workforce and were perceived as top quality individuals who conveyed a top-notch item. The Titanic in this manner was built to these demanding benchma...

Taylor Swift Who is she ? 10 facts about Taylor Swift !

 Taylor Swift #TaylorSwift   : About Taylor Swift Taylor Swift was born on december thirteen, 1989 in Reading, Pennsylvania, wherever she began writing her 1st songs at the age of 5, and once she turned sixteen, Swift discharged her 1st album and later  became one of the most well-liked pop and country and western singers. 1 Her grandma was an expert opera singer, and shortly Swift followed within the footsteps of her grandma, singing in several native events by her tenth year, like concerts and competitions 2 When she was eleven, she sang the american anthem "The Star-Spangled Banner" at the Philadelphia  Basketball Championship, and started to find out stringed instrument. 3 Taylor Swift   is usually visit nashville, Tennessee, the primary country music kiss so as to realize a career in music, co-writing some songs, and making an attempt to sign her 1st music contract. 4 Taylor Swift  released her 1st sin...

The New iPad | iPad 3

The, New, iPad, iPad 3, The New iPad | iPad 3 Not   i Pad  3  :  It  Is  (The  New  iPad) Before we talk about the new will begin our conversation (as it began the conference) is an interesting statistic: Did you know? Did you know that Apple has sold only in the last quarter of last year   ?, more than 15 million iPad device   ?  which sold more than any computer company in the world during the same period. The first thing that striking in the new iPad is a high-quality screen, which includes 3.1 million pixel quality 2048 × 1536 , making it the highest quality screen in all mobile devices at all, so much so that it can be higher than the human eye to see!! It's not only quality but also improve the color saturation of 44%. The   New   IPad works A5X new processor dual-core performance gives the best 4 times in graphics.. Have been improved 5 megapixel camera and became the possibi...