Skip to content

Instantly share code, notes, and snippets.

@Lovor01
Created September 23, 2023 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lovor01/18d035abca9f23438f3e9b0f0068ae44 to your computer and use it in GitHub Desktop.
Save Lovor01/18d035abca9f23438f3e9b0f0068ae44 to your computer and use it in GitHub Desktop.
WordPress: Unregister shortcut key ctrl+k (cmd+k)
wp.domReady( () => {
const unsubscribe = wp.data.subscribe( () => {
const command = wp.data.select( 'core/keyboard-shortcuts' ).getShortcutKeyCombination( 'core/commands' );
if ( command && command.character === 'k' ) {
wp.data.dispatch( 'core/keyboard-shortcuts' ).unregisterShortcut( 'core/commands' );
unsubscribe();
}
// in the future, more commands may be registered, so perhaps following change is needed:
// const shortcutsArray = wp.data.select( 'core/keyboard-shortcuts' ).getAllShortcutKeyCombinations( 'core/commands' );
// if ( shortcutsArray.length > 0 && shortcutsArray.some( el => el.character === 'k' ) ) {
} );
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment