Skip to content

Instantly share code, notes, and snippets.

@Lovor01
Forked from bfintal/cheatsheet.js
Last active March 8, 2023 22:29
Show Gist options
  • Save Lovor01/18227f4384a6d6b78802355f838d9ec7 to your computer and use it in GitHub Desktop.
Save Lovor01/18227f4384a6d6b78802355f838d9ec7 to your computer and use it in GitHub Desktop.
Block editor (Gutenberg) Cheat Sheet
// get current post categories
wp.data.select('core/editor').getEditedPostAttribute('categories')
wp.data.select('core/editor').getCurrentPostAttribute('categories')
// Get the data of a block
wp.data.select( 'core/editor' ).getBlocks()[0]
// Update attributes of another block
// wp.data.dispatch( 'core/editor' ).updateBlockAttributes( clientID, attributes )
wp.data.dispatch( 'core/editor' ).updateBlockAttributes( '10d88a6d-95d6-4e07-8293-5f59c83a26c0', { heading: 'New Heading' } )
// Get currently selected block.
wp.data.select( 'core/editor' ).getBlockSelectionStart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment