Skip to content

Instantly share code, notes, and snippets.

@dcooney
Last active April 28, 2023 18:18
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 dcooney/6be6abd45be04105a3de5628f9bc1f7b to your computer and use it in GitHub Desktop.
Save dcooney/6be6abd45be04105a3de5628f9bc1f7b to your computer and use it in GitHub Desktop.
Gutenberg Functions and Hooks
// Select a block.
wp.data.dispatch("core/block-editor").selectBlock(clientId);
// Update block attributes.
wp.data.dispatch("core/block-editor").updateBlockAttributes(clientId, { content: "<p>this is the new content</p>"});
// Replace a block.
wp.data.dispatch("core/block-editor").replaceBlock(
clientId,
wp.blocks.createBlock("core/image", {
id: attachment_id,
url: attachment_url,
alt: "This is the Alt Text",
caption: "This is the Caption",
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment