68 votes
Accepted

Enable Gutenberg on custom post type

For Gutenberg to work in a Custom Post Type you need to enable both the editor in supports (which you already have) and show_in_rest. So add 'show_in_rest' => true, to your post registration ...
  • 2,453
41 votes
Accepted

Check what Gutenberg blocks are in post_content

WordPress 5.0+ has a function for this: parse_blocks(). To see if the first block in the post is the Heading block, you'd do this: $post = get_post(); if ( has_blocks( $post->post_content ) ) { ...
38 votes

Custom taxonomy terms not showing as list Gutenberg Editor

I face the same as your problem and solved as the following you must add 'show_in_rest' => true, for both post_type and taxonomies int the last line of array such as register_post_type( '...
23 votes

How would I get a taxonomy/category list inside a Gutenberg block?

You don't need apiFetch or localization to get a list of all categories. You can do this with the wp.data module: wp.data.select('core').getEntityRecords('taxonomy', 'category'); See the Gutenberg ...
  • 331
23 votes

Where can I find the Gutenberg block icons?

Here you can find a list of all the Gutenberg icons with name and preview: https://wordpress.github.io/gutenberg/?path=/story/icons-icon--library In order to use this, you'll need to copy the actual ...
  • 958
22 votes
Accepted

Removing panels (meta boxes) in the Block Editor

The remove_meta_box() function will not work with the Block Editor, because these are now Panels and work differently. There is currently no documentation on how to disable Panels, but, let's dance. ...
  • 8,619
21 votes
Accepted

Running Gutenberg React in Development Mode

It took me way too long to find this but all you have to do is set SCRIPT_DEBUG to true. Simply add this line to wp-config.php: define('SCRIPT_DEBUG', true);
19 votes
Accepted

How to extend the gallery block in Gutenberg?

Ok, I've been playing with this for a little bit and have managed to change the output of the Gallery block, with the following caveats: The preview does not match the output. I think this is ...
18 votes
Accepted

WordPress adding scaled images that don't exist (1536x1536 and 2048x2048)

I found the culprit! WordPress 5.3 introduced additional image sizes which can be found via /wp-includes/media.php. Updating my function, like so, removed the extra sizes: function ...
  • 1,943
16 votes
Accepted

Gutenberg - remove / add blocks with custom script

There's probably a simpler way to do this, and if there isn't you should open an issue on the Gutenberg GH issue tracker ( the API is not set in stone ). Because the API is not set in stone, this ...
  • 53.8k
16 votes
Accepted

Allow excerpt for pages in Gutenberg?

It's nothing new with the block editor, it's the same age-old way by putting the following code into your theme's functions.php: add_action( 'init', 'wpse325327_add_excerpts_to_pages' ); function ...
16 votes
Accepted

Where can I find the Gutenberg block icons?

Gutenberg is making use of dashicons. You can find your example icon here, and a cheat sheet of dashicons here.
  • 486
16 votes
Accepted

How to remove the core embed blocks in WordPress 5.6?

With WordPress 5.6 (Gutenberg v8.8.0), the implementation of the core-embed/* blocks changed (see pull request #24090: Refactor embed block to single block with block variations). There are now 43 ...
  • 3,435
15 votes
Accepted

Validation error: Extending Gutenberg gallery block

Answering my own question: As suggested by WebElaine I created a completely new block to fix the problem. To make this task easier, I used create-guten-block by Ahmad Awais, which is pretty easy to ...
  • 321
15 votes
Accepted

Gutenberg editor add a custom category as wrapper for custom blocks

Digging myself deeper in documentation, I got the following result. There is a way to group your custom blocks around a given category in Gutenberg, and therefore we have the method ...
  • 824
15 votes

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 ...
15 votes
Accepted

Add pre-publish conditions to the block editor

EDIT Sept 2021: An updated version of the answer that uses hooks. This version tracks changes in the editor much better. It also uses import statement instead of importing directly from the wp global. ...
  • 3,433
13 votes

Trigger Javascript on Gutenberg (Block Editor) Save

Not sure if there is a better way, but I am listening to subscribe rather than adding an event listener to the button: wp.data.subscribe(function () { var isSavingPost = wp.data.select('core/editor'...
  • 277
13 votes
Accepted

How to detect the usage of Gutenberg

There are several variants: WordPress 4.9, Gutenberg plugin is not active WordPress 4.9, Gutenberg plugin is active WordPress 5.0, Block Editor by default WordPress 5.0, Classic Editor plugin is ...
  • 1,777
13 votes

What are all the query parameters for getEntityRecords?

If you look into the source code for getEntityRecords, you'll see that the the core/data library creates entities using the Wordpress API in entities.js. So you can use any parameter available in the ...
13 votes
Accepted

Deactivate Gutenberg tips forever - not Gutenberg

Update #1: After asking from @leymannx I checked how these settings are stored. It turned out that settings are not permanent, they are saved in the browser as localStorage. key: WP_DATA_USER_{id}:...
  • 4,262
12 votes

How to add a custom CSS class to core blocks in Gutenberg editor?

You have second and third arguments with this hook you can use the second to get the block type. https://wordpress.org/gutenberg/handbook/extensibility/extending-blocks/ A filter that applies to ...
  • 1,733
12 votes

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 ...
  • 7,274
12 votes
Accepted

How to use PanelColorSettings in custom Gutenberg block?

First you need to import the component - const { PanelColorSettings, } = wp.editor; then inside the InspectorControls you call the component <PanelColorSettings title={ ...
12 votes
Accepted

How do I get the current post ID within a Gutenberg/Block Editor block?

To simply get the value you can call the selector: const post_id = wp.data.select("core/editor").getCurrentPostId(); In this case, the post id won't change, so you could assign the value to ...
  • 2,453
12 votes

Get the current block ID

The block id is saved in the clientId field. It's regenerated at each save of the post and is only available in props in the edit function. In order to use this field as unique id in the save function,...
  • 161
12 votes
Accepted

Remove block styles in the Block Editor

We start off by finding out which block styles exists via .getBlockTypes(). This will dump it into the console: wp.domReady(() => { // find blocks styles wp.blocks.getBlockTypes().forEach((...
  • 8,619
12 votes
Accepted

How to use “getEntityRecords” for user data?

So I guess you're still using WordPress version 5.3.x? :) Because if so (and I was), then yes, the users endpoint (at wp/v2/users) is not included in the default entities. But you can manually add ...
  • 33.6k
11 votes

Gutenberg disallow certain custom blocks but keep all core blocks?

There's a whitelist blocks removal example from the Gutenberg Handbook: var allowedBlocks = [ 'core/paragraph', 'core/image', 'core/html', 'core/freeform' ]; wp.blocks.getBlockTypes()...
  • 64.7k
10 votes

check if Gutenberg is currently in use

The function is_gutenberg_page is from the Gutenberg plugin, while the is_block_editor method is available from 5.0. This function below combines both into a single checking function. The code below ...

Only top scored, non community-wiki answers of a minimum length are eligible