Last active
April 11, 2024 00:22
-
-
Save bfintal/beebe46593df25326c0271f4cb227d96 to your computer and use it in GitHub Desktop.
Gutenberg Cheat Sheet
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
// Get the data of a block | |
wp.data.select( 'core/block-editor' ).getBlocks()[0] | |
// Update attributes of another block | |
// wp.data.dispatch( 'core/editor' ).updateBlockAttributes( clientID, attributes ) | |
wp.data.dispatch( 'core/block-editor' ).updateBlockAttributes( '10d88a6d-95d6-4e07-8293-5f59c83a26c0', { heading: 'New Heading' } ) | |
// Get currently selected block. | |
wp.data.select( 'core/block-editor' ).getBlockSelectionStart() | |
// Count the total number of blocks in the editor (includes even nested) | |
var a = innerBlocks => { | |
return innerBlocks.length + innerBlocks.reduce( ( sum, block ) => { | |
return sum + a(block.innerBlocks) | |
}, 0 ) | |
} | |
a( wp.data.select( 'core/block-editor' ).__unstableGetClientIdsTree() ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment