Skip to content

Instantly share code, notes, and snippets.

@mawiswiss
Last active December 4, 2025 20:39
Show Gist options
  • Select an option

  • Save mawiswiss/738700048bc85dff1b8b7aaedf277352 to your computer and use it in GitHub Desktop.

Select an option

Save mawiswiss/738700048bc85dff1b8b7aaedf277352 to your computer and use it in GitHub Desktop.
Prevent rich text pastes from including formatting ini WordPress Gutenberg
wp.domReady(() => {
function pasteAsPlainText(e) {
if (!e.clipboardData) return;
e.stopPropagation();
e.preventDefault();
const text = e.clipboardData.getData('text/plain');
// Insert plain text at the caret
document.execCommand('insertText', false, text);
}
// capture paste events inside the editor
document.addEventListener('paste', pasteAsPlainText, true);
});
// Try "__unstablePastePlainText={true}" in the RichText component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment