show_admin_bar()WP 3.1.0

Allows you to disable the "Toolbar" (Admin Bar). Technically, the function enables/disables "Admin Bar" for the front-end. You cannot turn it off in Admin-panel.

You can call this function at an early stage, even before plugins loaded. Normally the function used in functions.php file. There is no need to call the function during the init event.

This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.

There's also a show_admin_bar filter that allows to turn OFF/ON the Toolbar, and it has higher priority than this function:

add_filter( 'show_admin_bar', '__return_false'); // turn off
add_filter( 'show_admin_bar', '__return_true');  // turn on

Note: "Admin Bar" was renamed with "Toolbar" since WordPress Version 3.3.

No Hooks.

Return

null. Nothing.

Usage

show_admin_bar( $show );
$show(true|false) (required)
Whether to allow the admin bar to show.

Examples

0

#1 Soft shutdown Toolbar [auto-translate]

Suppose we need to disable the "Toolbar" in the front of the site. But at the same time, we need to allow plugins, to enable the panel through the filter show_admin_bar.

To do this, insert the following line into the theme functions.php file:

show_admin_bar( false );
0

#2 Soft Panel Shutdown for everyone except the admin [auto-translate]

To do this, use the current_user_can() function:

add_action( 'init', function(){

	if ( ! current_user_can( 'manage_options' ) ) {
		show_admin_bar( false );
	}

} );
0

#3 Hard disconnect is a higher priority than show_admin_bar() [auto-translate]

To do this, use the show_admin_bar hook - see link for examples.

Notes

  • Global. true|false. $show_admin_bar

Changelog

Since 3.1.0 Introduced.

Code of show_admin_bar() WP 6.0

function show_admin_bar( $show ) {
	global $show_admin_bar;
	$show_admin_bar = (bool) $show;
}