Add a containing DIV to core Gutenberg blocks

I’m sure there are other ways e.g. with CSS only or Add custom class to core blocks in Gutenberg, but regarding: Add a containing DIV to core Gutenberg blocks one way could be with the render_block filter: add_filter( ‘render_block’, function( $block_content, $block ) { // Target core/* and core-embed/* blocks. if ( preg_match( ‘~^core/|core-embed/~’, $block[‘blockName’] … Read more

How to Disable Gutenberg & Return to the Classic WordPress Editor Without any Plugins

Simply add the following to functions.php file of your current theme. <?php /** * Disable Gutenberg for supported posts. */ add_filter( ‘use_block_editor_for_post_type’, ‘__return_false’, 100 ); /** * Disable Gutenberg action and filter hooks. */ function df_disable_gutenberg_hooks() { remove_action( ‘admin_menu’, ‘gutenberg_menu’ ); remove_action( ‘admin_init’, ‘gutenberg_redirect_demo’ ); remove_filter( ‘wp_refresh_nonces’, ‘gutenberg_add_rest_nonce_to_heartbeat_response_headers’ ); remove_filter( ‘get_edit_post_link’, ‘gutenberg_revisions_link_to_editor’ ); remove_filter( ‘wp_prepare_revision_for_js’, … Read more

Gutenberg: Restrict Top Level Blocks, But Not Child Blocks

The short answer is you can’t. But you can accomplish this by using a block template that only contains your block and is locked. If your block has an InnerBlocks instance, you can add any of the registered blocks to it. add_action( ‘init’, ‘insert_template’ ); function insert_template() { $post_type_object = get_post_type_object( ‘post’ ); $post_type_object->template =[ … Read more

How to Add extra option to Image Block Settings?

This can be done using block filters. First, you’ll need to filter block attributes for the image block to be able to save the new items: const { addFilter } = wp.hooks; function filterAttributes( settings, name ) { if ( ‘core/image’ === name && settings.attributes ) { settings.attributes.description = { type: ‘string’, default: ” }; … Read more

How to enable Gutenberg Block Editor on taxonomy term pages?

As mentioned in the comments, it isn’t currently supported, although there is an open issue for exactly this feature: https://github.com/WordPress/gutenberg/issues/17099 Meanwhile, I can think of a couple of ways to achieve the same effect: 1) Pages + custom rewrites As you suggested in your question, you could create a set of parallel pages with the … Read more

How does the Gutenberg mobile/tablet/desktop preview work with media queries?

I investigated the states set using React Dev Tools and found the preview modes are set under the deviceType key. Went through the Gutenberg source and came across the __experimentalGetPreviewDeviceType function. /** * Returns the current deviceType. */ const { deviceType } = useSelect( select => { const { __experimentalGetPreviewDeviceType } = select( ‘core/edit-post’ ); … Read more

How to define a Block Style in an Innerblocks template

I can’t determine the syntax to use (or if it is even supported) to define the blocks’ style. For example, I would like the Button to use the “Outline” style instead of its default “Fill” style. Yes it’s supported and the syntax is quite easy. Excerpt from the block styles documentation: Block Styles allow alternative … Read more