5 votes
Accepted

How to add code to `head` with WordPress 5.9 FSE (Full Site Editing)

As far as I understand the wp_head and wp_footer actions should still work under FSE in WP 5.9+, through the template canvas PHP file that's loaded through the locate_block_template(). That PHP file ...
user avatar
  • 64.4k
4 votes

Setting default font family with theme.json

I had the same problem and I find out how to solve it: For each "fontFamily" inside "fontFamilies" array, you get a custom variable. From your example You can use both variables on ...
user avatar
  • 41
4 votes
Accepted

Is it possible to create column width presets in Gutenberg?

Just in case anyone else comes looking here's what I did. First I enqueued a javascript file into the block editor. add_action( 'enqueue_block_editor_assets', function () { wp_enqueue_style( '...
user avatar
4 votes
Accepted

@wordpress/components Button variants not styled

The WordPress components docs are pulled from the development branch of the repository, meaning they may describe features and functionality that have yet to be released. With the current version of ...
user avatar
4 votes

How to create multiple Gutenberg blocks in one plugin

I've updated this answer with more than one way to accomplish this. Though maybe it could go without saying the context of these is using the @wordpress/scripts package for development. Single bundle ...
user avatar
  • 406
4 votes
Accepted

Where are the layout defaults in Twenty Twenty Two coming from?

there's a layout option for the post content block that says it will inherit the default layout. Where is that default coming from? In block themes, the default layout settings (contentSize and ...
user avatar
  • 33k
3 votes
Accepted

Gutenberg - button to parse and format all blocks?

I think you can do this in a couple of different ways. I can't help with the specific processing you want done (since I don't know exactly what all you want done) but hopefully this gets you started. ...
user avatar
  • 351
3 votes

Add colors to existing color palette without replacing it

To expand on Vitatus' answer, it works best if you're using a child theme, or a plugin, that edits the above. Assuming that the editor-colour-palette is called within a action with a default priority, ...
user avatar
3 votes
Accepted

Creating Block templates with 'core/heading' other than level 2

A new day, and refreshed Google-fu powers provided the simple answer: The level attribute needs to be an integer, not a a string. [ 'core/heading', [ 'level' => 3, 'placeholder' =>...
user avatar
  • 362
3 votes

How do you use __experimentalLayout to give innerblocks alignment control and default layout?

You're pretty close. Specifying layout details in block.json should nest inside a "default" property. Doing so will have the Layout panel display accordingly but there's more to it than that....
user avatar
  • 406
3 votes
Accepted

What is the significance of 'root' in getEntityRecords?

The important thing to note is that post is a kind/sub-type of the post types entity, all posts regardless of type share the same table and general data structure and fields etc. This contrasts with ...
user avatar
  • 53.2k
3 votes

Custom Gutenberg Block: Excluding an allowed block from InnerBlock's templateLock={'all'}

core/buttons is a container block, it's not the actual buttons. Instead, core/buttons contains core/button blocks. The same way that a core/columns block contians core/column blocks. You need to add ...
user avatar
  • 53.2k
3 votes
Accepted

Custom Gutenberg Block: How to return plain HTML with save(), without escaping?

From the docs: While it is possible to return a string value from save, it will be escaped. If the string includes HTML markup, the markup will be shown on the front of the site verbatim, not as the ...
user avatar
  • 5,955
3 votes
Accepted

What is the "correct" way to add hooks or similar PHP behavior to a blocktheme?

I'm not the most experienced in block themes, but from what I've seen of them so far I feel pretty confident in saying that the functionality you describe should be implemented as a block. But it's ...
user avatar
2 votes
Accepted

Get a Wordpress Gutenberg Block Attribute to use it in frontend

One way of getting a unique id for a block in Gutenberg is using the clientId, but in a different way. Given that clientId string is used only once, you can store that in the attributes of the block, ...
user avatar
  • 181
2 votes

How to query multiple post types inside Gutenberg options panel?

Since while I was doing research I stumbled accross this thread, but it didn't bring me to the result I wanted. So I decided to register here to point out my approach to aquire the need of fetching ...
user avatar
  • 21
2 votes

How insert negative values in Gutenberg box-control

It can be done through inputProps prop. Check below example: <BoxControl label={ __('Margin', 'text-domain') } onChange={ (margins) => setAttributes({margins}) } inputProps={{ min: -300 ...
user avatar
2 votes
Accepted

Limit Gutenberg blocks available to users to choose from

In the functions.php file I added add_filter( 'allowed_block_types_all', 'func_allowed_block_types' ); function func_allowed_block_types( $allowed_blocks ) { return array( 'core/embed' ...
user avatar
2 votes
Accepted

How to set the localization for a Gutenberg block?

Summary: Perhaps like me, you just need to rename, relocate and/or manually load your script/JSON translations files? So I created a block using the npx @wordpress/create-block gutenpride command, ...
user avatar
  • 33k
2 votes

Custom button block doesn't work

I'd recommend looking at how the existing Button component works to get a sense of how Gutenberg does things. Specifically it uses a <RichText/> component (instead of a native <input>) ...
user avatar
  • 351
2 votes
Accepted

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 "...
user avatar
  • 33k
2 votes
Accepted

Disable only one Gutenberg block programatically / coblock/maps not listed in blocks

You'll want to target the block specifically via javascript. Brief example: wp.domReady(function() { wp.blocks.unregisterBlockType( 'coblocks/map' ); }); Save that to a js file and enqueue it via ...
user avatar
  • 362
2 votes

How to get featured_media of a post with getEntityRecords?

I found the solution... must use getEntityRecord not getEntityRecods: select("core").getEntityRecord("postType", "attachment", post.featured_media);
user avatar
  • 120
2 votes

What replaces wpColorPicker in Gutenberg?

I ended up implementing my own ColorControl. I'm not satisfied with this solution and I don't advice you to follow this route blindly. However, if you want to get the job done and don't want to spend ...
user avatar
2 votes
Accepted

Gutenberg custom block using only register_block_type() and HTML

No, blocks are built with more than HTML - they need JS and PHP. However, you could add an HTML block wherever you need it, then click the More Options dots in the block's toolbar, click Add to ...
user avatar
  • 8,746
2 votes
Accepted

Gutenberg: Heading with subheading/paragraph

In this case it seems a block pattern might suffice. The Group block has a templateLock attribute which can be set to all to prevent any additional blocks from being inserted within and also keep the ...
user avatar
  • 406
2 votes
Accepted

Gutenberg: How to use RangeControl in the editor itself and make it work?

This happens because the Component need the correct data type. Use "number" when getting the value. Use "String" as the attributes type. const onChangeValue = ( newValue ) => { ...
user avatar
  • 579
2 votes
Accepted

Gutenberg: How to display meta field data in the block frontend (save function)

From the docs: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save Note: The save function should be a pure function that depends only on the attributes used ...
user avatar
  • 406
2 votes

How to only load css for used blocks on frontend

To get separate files for each block you'll need to bring your own webpack config One as simple as this should work: const defaultConfig = require('@wordpress/scripts/config/webpack.config'); module....
user avatar
  • 406
2 votes
Accepted

Correctly handling WordPress core data retrieval in Gutenberg

So... through some trial and error, I discovered that I'd gotten some of the logic wrong in order to detect and ensure the result of the API call (and subsequent state change) was treated properly. I ...
user avatar

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