71 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 ...
Alvaro's user avatar
  • 2,573
45 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 ) ) { ...
Jacob Peattie's user avatar
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( '...
Ali Gamaan's user avatar
28 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 ...
Jules's user avatar
  • 1,078
26 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. ...
Christine Cooper's user avatar
  • 8,768
25 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);
Zeevruchtje's user avatar
25 votes
Accepted

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 ...
Aaron's user avatar
  • 366
21 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.
moped's user avatar
  • 536
20 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 ...
Jacob Peattie's user avatar
20 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 ...
Sam's user avatar
  • 2,126
19 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 ...
Mayeenul Islam's user avatar
18 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 ...
Sven's user avatar
  • 3,624
17 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 ...
Josh Bradley's user avatar
17 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 ...
HU is Sebastian's user avatar
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 ...
Tom J Nowell's user avatar
  • 58.8k
16 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 ...
Andreas's user avatar
  • 331
16 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 ...
fefe's user avatar
  • 874
16 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. ...
Welcher's user avatar
  • 3,578
16 votes
Accepted

How do I access site and block editor state data and use `useSelect()` or `withSelect()` to bind it to my components?

✨ Intro to the Gutenberg Data Module ✨ Gutenberg's core data model shares a lot of the API and ideology of the state-management library Redux, with a number of differences. Reading up on Redux can ...
bosco's user avatar
  • 6,785
15 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 ...
Fayaz's user avatar
  • 8,899
15 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'...
tomyam's user avatar
  • 307
14 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 ...
Alvaro's user avatar
  • 2,573
13 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={ ...
Ashiquzzaman Kiron's user avatar
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 ...
KAGG Design's user avatar
  • 1,832
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}:...
nmr's user avatar
  • 4,481
13 votes
Accepted

`is_admin` returning false in backend in server side rendered block

If you have a server side rendered block in the backend, it is rendered via the REST API endpoint /wp/v2/block-renderer/xyz/blockname. This endpoint calls your render function. In the frontend the ...
Sören Wrede's user avatar
13 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 ...
Sally CJ's user avatar
  • 38.8k
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 ...
Shibi's user avatar
  • 1,803
12 votes
Accepted

Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?

The reusable block is registered with the core/block name. I tried to add it to the allowed blocks in the allowed_block_types filter, here's an example: add_filter( 'allowed_block_types', '...
birgire's user avatar
  • 66.9k
12 votes
Accepted

Gutenberg disallow certain custom blocks but keep all core blocks?

AFAIK there is only one way to remove blocks from Gutenberg - you have to use allowed_block_types filter. Unfortunately Gutenberg developers are not very familiar with WordPress hooks and filters, so ...
Krzysiek Dróżdż's user avatar

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