check if Gutenberg is currently in use

Necessary API Functions/Methods: You’ll need WP_Screen::is_block_editor() method to check if you are currently in the Gutenberg Editor (Since WordPress 5.0). Also, if you install Gutenberg as a separate plugin, then you’ll have the is_gutenberg_page() function available to do the same check. So for an overall solution, you’ll need to combine these two. Of course, this … Read more

Gutenberg: Is there a way to know if current block is inside InnerBlocks?

getBlockParents will work accurately. You can use getBlockParents with the clientId of the block, getBlockParents will return the all parent blocks id if the current block is under any Blocks. It will return blank if current block is not under any Block here is a method that you can use: const innerBlock = “namespace/block-name”; const … Read more

Load CSS/Javascript in frontend conditionally if block is used

Well, the styles and scripts you register in your php register_block_type call should only be loaded when the block is in use if i recall correctly. If you want to load additional scripts or styles to be enqueued only if there is a block of type “my-awesome/block-type”, you can use the has_block function in your … Read more

How would one modify the filtering Gutenberg applies to pasted content?

In my blocks.js , located in wp-includes/js/dist/ I find the RemoveInvalidHTML function, which seems to responsible for removing styles from pasted HTML. /** * Given a schema, unwraps or removes nodes, attributes and classes on HTML. * * @param {string} HTML The HTML to clean up. * @param {Object} schema Schema for the HTML. * … Read more