Title: wp_admin_bar_command_palette_menu
Published: May 20, 2026

---

# wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#wp--skip-link--target)

Adds the command palette trigger button.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#description)󠁿

Displays a button in the admin bar that shows the keyboard shortcut for opening 
the command palette.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#parameters)󠁿

 `$wp_admin_bar`[WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
required

The [WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
instance.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#source)󠁿

    ```php
    function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
    	if ( ! is_admin() || ! wp_script_is( 'wp-core-commands', 'enqueued' ) ) {
    		return;
    	}

    	$shortcut_labels = array(
    		'appleOS' => _x( '⌘K', 'keyboard shortcut to open the command palette' ),
    		'default' => _x( 'Ctrl+K', 'keyboard shortcut to open the command palette' ),
    	);
    	$apple_pattern   = 'Macintosh|Mac OS X|Mac_PowerPC';
    	$is_apple_os     = (bool) preg_match( "/{$apple_pattern}/i", $_SERVER['HTTP_USER_AGENT'] ?? '' );
    	$shortcut_label  = $is_apple_os ? $shortcut_labels['appleOS'] : $shortcut_labels['default'];
    	$title           = sprintf(
    		'<span class="ab-icon" aria-hidden="true"></span><span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span>',
    		$shortcut_label,
    		/* translators: Hidden accessibility text. */
    		__( 'Open command palette' ),
    	);
    	/*
    	 * Detect Apple OS via JavaScript for sites behind a CDN blocking the UA header.
    	 *
    	 * Running the script as the admin bar is rendered avoids a flash of incorrect content
    	 * for users with Apple OS when the UA header is blocked. It also prevents the need for
    	 * wp-i18n to be loaded as a dependency.
    	 */
    	$function = <<<'JS'
    		( applePattern, appleOSLabel ) => {
    			if ( ! ( new RegExp( applePattern, 'i' ) ).test( navigator.userAgent ) ) {
    				return;
    			}
    			const kbd = document.querySelector( '#wp-admin-bar-command-palette .ab-label kbd' );
    			if ( kbd ) {
    				kbd.textContent = appleOSLabel;
    			}
    		}
    	JS;
    	$script   = sprintf(
    		'( %s )( %s, %s );',
    		$function,
    		wp_json_encode( $apple_pattern, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
    		wp_json_encode( $shortcut_labels['appleOS'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
    	);
    	$script  .= "\n//# sourceURL=" . rawurlencode( __FUNCTION__ );
    	$wp_admin_bar->add_node(
    		array(
    			'id'    => 'command-palette',
    			'title' => $title,
    			'href'  => '#',
    			'meta'  => array(
    				'class'   => 'hide-if-no-js',
    				'onclick' => 'wp.data.dispatch( "core/commands" ).open(); return false;',
    				'html'    => wp_get_inline_script_tag( $script ),
    			),
    		)
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/admin-bar.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/admin-bar.php#L947)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/admin-bar.php#L947-L1002)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_inline_script_tag/)`wp-includes/script-loader.php` |

Constructs an inline script tag.

  | 
| [wp_script_is()](https://developer.wordpress.org/reference/functions/wp_script_is/)`wp-includes/functions.wp-scripts.php` |

Determines whether a script has been added to the queue.

  | 
| [WP_Admin_Bar::add_node()](https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/)`wp-includes/class-wp-admin-bar.php` |

Adds a node to the menu.

  | 
| [wp_json_encode()](https://developer.wordpress.org/reference/functions/wp_json_encode/)`wp-includes/functions.php` |

Encodes a variable into JSON, with some confidence checks.

  | 
| [_x()](https://developer.wordpress.org/reference/functions/_x/)`wp-includes/l10n.php` |

Retrieves translated string with gettext context.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [is_admin()](https://developer.wordpress.org/reference/functions/is_admin/)`wp-includes/load.php` |

Determines whether the current request is for an administrative interface page.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_admin_bar_command_palette_menu/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_admin_bar_command_palette_menu%2F)
before being able to contribute a note or feedback.