We can use filters to disable autocompleters in the WordPress block editor. By default, the block editor registers three autocompleters: users, links, and blocks. To see what autocompleters are registered in our block editor, we can write something like this in the browser console:
const getCompleters = (completers) => { console.log(completers) };
wp.hooks.addFilter('editor.Autocomplete.completers', 'my-example-namespace', getCompleters);
Now when we take any action that fires one of the autocompleters (such as searching for a block in the block appender), we’ll see an array of objects logged to the console:
Disable an autocompleter
Let’s say we want to disable the links autocompleter, which enables users to search for posts to link by typing [[ followed by a string of text.
To do this we can write an addFilter just like the one used above to log out a list of autocompleters. In this case, our filter callback function will instead use the JavaScript array filter method to remove the links object from the autocompleters array:
const disableLinksCompleter = (completers) => (
completers.filter((content) => 'links' !== content.name)
);
wp.hooks.addFilter('editor.Autocomplete.completers', 'my-example-namespace', disableLinksCompleter);
After applying this filter, we will no longer see a list of matching posts populated when typing [[ in the block editor.
Looking to change the trigger (character combination) used for one or more autocompleters in the WordPress block editor? I wrote a separate blog post about that here.