2

I'm developing a Gutenberg block and have a doubt on using the latest gutenberg APIs.

My block contains a button. Referring the docs, there is a property called "variant" using which the button style can be changed.

I was testing this in WordPress 5.7.2 (the latest WP released as of now) and this property does not work.

https://developer.wordpress.org/block-editor/reference-guides/components/button/#variant https://github.com/WordPress/gutenberg/pull/31713

enter image description here

Docs no where mentions that this applies to WP 5.8+. Being new to this ecosystem makes be doubt that if I'm doing things right.

So if I use this API, then users who use the plugin on older WP version will not get this working right ?

What are the best practises on this ? Shouldn't the doc be updated after WP 5.8 is released ?

I do not want to change the minimum required WP version for my plugin, since this block is not the main feature in my case. Please advise.

1 Answer 1

0

I'm not sure that component is meant to be used on the front end, it looks as though that's mainly there for creating buttons in the editor itself.

For block "variations", there are block styles, which might be what you're looking for: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/. Block styles are the native way of having multiple ways of presenting a block, for example the core button block has a default solid style and an outline style.

1
  • Thanks, the button will be present only the editor and not on the frontend. But my concern is not specific to this button but the overall best practices in following the WordPress doc for block APIs. In my case as you saw, someone following the doc wouldn't get it to work as it applies only to future WP version. Commented Jul 5, 2021 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.