add_admin_bar_menusaction-hookWP 3.1.0

Fires immediately after WordPress creates the basic admin bar items.

It can be used to add or remove toolbar items.

Execution order:

  1. add_admin_bar_menus
  2. admin_bar_menu$wp_admin_bar can be used here without declaring it global.
  3. wp_before_admin_bar_render
  4. wp_after_admin_bar_render

Use a priority from 0–99 to position a custom item correctly relative to system items.

Sometimes it is more convenient to use the similar admin_bar_menu hook, which fires afterward and passes the WP_Admin_Bar object to the callback function.

Usage

add_action( 'add_admin_bar_menus', 'wp_kama_add_admin_bar_menus_action' );

/**
 * Function for `add_admin_bar_menus` action-hook.
 * 
 * @return void
 */
function wp_kama_add_admin_bar_menus_action(){

	// action...
}

Examples

#1 Usage demonstration

add_action( 'add_admin_bar_menus', 'add_toolbar_node', 80 );
function add_toolbar_node() {
	global $wp_admin_bar;

	$wp_admin_bar->add_node(
		[
			'id'    => 'my-link',
			'title' => 'Home',
			'href'  => home_url(),
		]
	);
}

#2 Remove basic items (links) from the toolbar

Changelog

Since 3.1.0 Introduced.

Where the hook is called

WP_Admin_Bar::add_menus()
add_admin_bar_menus
wp-includes/class-wp-admin-bar.php 680
do_action( 'add_admin_bar_menus' );

Where the hook is used in WordPress

Usage not found.