Created
September 23, 2023 20:47
-
-
Save Lovor01/18d035abca9f23438f3e9b0f0068ae44 to your computer and use it in GitHub Desktop.
WordPress: Unregister shortcut key ctrl+k (cmd+k)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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