How to Build an Accessible Command-K Search Palette in WordPress With Vanilla JS
1. Why Traditional WordPress ?s= Search Pages Feel Dated
Standard WordPress search forces visitors to type a query, submit a form, wait for an uncached PHP page reload, and scan a generic vertical list. For multi-niche portfolios, documentation hubs, and theme marketplaces like Kiln’s 200-edition archive, a native HTML <dialog> Command-K palette delivers instant feedback on every keystroke.
Using <dialog.showModal()> gives you native Escape-key dismissal, backdrop styling via ::backdrop, and built-in focus trapping without installing a single external React or modal dependency.

document.addEventListener( 'keydown', function ( e ) {
if ( ( e.metaKey || e.ctrlKey ) && e.key.toLowerCase() === 'k' ) {
e.preventDefault();
document.getElementById( 'cmd-palette' ).showModal();
}
} );
2. Keyboard Navigation, Arrow Keys & Live Region Announcements
A great Command-K palette should feel effortless without touching a mouse. Bind ArrowDown and ArrowUp to move an aria-selected="true" highlight across matching rows, and trigger navigation when the user presses Enter. Debouncing input filtering is unnecessary when searching <500 items in memory—filtering synchronously on input keeps perceived latency under 1ms.
FAQ — Does embedding a 200-item JSON index bloat HTML? A compact array of title, slug, and category tags for 200 items compresses to roughly 5–8KB gzipped—far lighter than a single thumbnail image.