Control When To Display WordPress Admin Bar


On day 10 of our Advent Calendar we show a little code snippet for the WordPress Admin Bar. At first the easiest way to remove the Admin Bar with new function __return_false; include since WordPress 3.0.

add_filter( 'show_admin_bar', '__return_false' );

Small Note: It give similar functions for return true __return_true, return zero __return_zero and return empty array __return_empty_array.

If you like to deactivate the Admin Bar completely, you can use the following syntax and if you want adjust or extend. This example just lets user use the Admin Bar, who have the rights manage_options, in default only the administrator hast the rights.

function fb_show_admin_bar() {
	
	if ( current_user_can( 'manage_options' ) )
		return TRUE;
	else
		return FALSE;
}
add_filter( 'show_admin_bar', 'fb_show_admin_bar' );

Comments are closed.

2 comments

  1. Cor van Noorloos

    Hi Frank,

    Using above on about every WordPress site I run I wondered if it would be possible to remove its setting from the user profile as well?

    http://24design.net/wp-content/uploads/2010/12/show-admin-bar.png

    Best regards,

    Cor van Noorloos

  2. Frank

    Yes, i jad found this also, but later and my code is only for a plugin or theme functions.
    Thanks!