A WordPress plugin that demonstrates how to extend the Command Palette API with custom commands. The Command Palette (triggered with ⌘K or Ctrl+K) allows users to quickly access actions and navigate WordPress admin.
This plugin showcases five different command types using various registration methods:
Quick access to WordPress developer documentation directly from the command palette:
- Block Editor Handbook
- Plugin Developer Handbook
- Theme Developer Handbook
- REST API Handbook
Activate or deactivate any installed plugin directly from the command palette. Only available outside the block editor context.
Opens a modal showing the 5 most recently modified posts with:
- Creation and modification dates
- Quick links to view or edit each post
Copies the current post's block content to your clipboard. Only available when editing a post with content.
Displays a breakdown of all blocks used in the current post/page, including nested blocks. Only available for viewable post types.
- Clone or download this repository into your WordPress
wp-content/plugins/directory - Install dependencies:
npm install
- Build the plugin:
npm run build
- Activate the plugin in WordPress admin
Start the development server with hot reloading:
npm run startBuild for production:
npm run buildThis plugin demonstrates three different approaches to registering commands with the WordPress Command Palette API:
Use dispatch(commandsStore).registerCommand() for commands that should be available across all admin pages:
import { dispatch } from "@wordpress/data";
import { store as commandsStore } from "@wordpress/commands";
dispatch(commandsStore).registerCommand({
name: "my-plugin/my-command",
label: "My Command",
callback: () => { /* action */ },
});Use the useCommand hook for commands tied to specific contexts (e.g., only in the editor):
import { useCommand } from "@wordpress/commands";
useCommand({
name: "my-plugin/editor-command",
label: "Editor Command",
context: "entity-edit", // Only in post/page editor
callback: ({ close }) => { /* action */ },
});Use useCommandLoader for commands that need to be generated dynamically based on data:
import { useCommandLoader } from "@wordpress/commands";
useCommandLoader({
name: "my-plugin/dynamic-loader",
hook: useMyCustomCommands, // Returns { commands, isLoading }
});- Global: Available everywhere in WordPress admin
site-editor: Available in the Site Editorentity-edit: Available when editing posts, pages, or other entities
- WordPress 6.3+ (Command Palette API)
- Node.js 18+
- npm 9+
@wordpress/scripts- Build tooling@wordpress/icons- Icon componentsawait-to-js- Async/await error handling utility
GPL-2.0-or-later