Admin Toolbar menu has new, higher priority values

In WordPress 6.6, the Search form moved to a high priority to position it at the end of the menu without using the CSSCSS Cascading Style Sheets. float property. Then WordPress 6.6.1 moved the User Profile menu and Recovery Mode to a high priority to keep them near the Search form.

  • Search form ('search') from 4 to 9999
  • User Profile ('my-account') from 7 to 9991
  • Exit Recovery Mode ('recovery-mode') from 8 to 9992

Using get_node() to manipulate one of these nodes in the admin_bar_menu hook would require a higher priority now (such as 9999).

To edit coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. items without setting a specific priority, functions can hook into wp_before_admin_bar_render instead. That requires declaring the $wp_admin_bar global.

Example: Replacing “Howdy” with “Hello” in the top profile link and in the ARIA label for its submenu

/**
 * Replaces the "Howdy" text in the WP admin toolbar.
 *
 * @global WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
 */
function wpdocs_replace_howdy_in_admin_bar() {
	global $wp_admin_bar;

	$my_account = $wp_admin_bar->get_node( 'my-account' );

	// Return early if node contents are not available to edit.
	if ( ! isset( $my_account->title ) || ! isset( $my_account->meta['menu_title'] ) ) {
		return;
	}

	$wp_admin_bar->add_node(
		array(
			'id'    => 'my-account',
			'title' => str_replace( 'Howdy,', 'Hello,', $my_account->title ),
			'meta'  => array(
				'menu_title' => str_replace( 'Howdy,', 'Hello,', $my_account->meta['menu_title'] ),
			),
		)
	);
}
add_action( 'wp_before_admin_bar_render', 'wpdocs_replace_howdy_in_admin_bar' );

See #61738, #61615, and #60685 for more details.


Props to @audrasjb, @joedolson, and @hellofromtonya for proofreading.

#6-6, #dev-note, #dev-notes, #dev-notes-6-6