Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks

Try the suggestion below: This assumes the <figure> element holding an image has a data-display-alignment attribute to match the alignment class applied attached that is somehow surfaced as a parameter in the wp_calculate_image_sizes hook: /** * Add custom image sizes attribute to enhance responsive image functionality * for content images. * * @param string $sizes … Read more

What is the advantage of ‘register_block_type’ (the PHP function) when creating custom blocks?

1.: The register_block_type lets you load additional stylesheets and scripts for your block in the frontend 2.: As you yourself wrote, register_block_type lets you define a dynamic php render_callback function 3.: If you use a render_callback, you can of course use filters within it. EDIT: As the comments pointed out, there is some clarification needed … Read more

How to only enqueue block javascript on the frontend when its needed [duplicate]

To register scripts/styles conditionally if the page has a certain block you can follow the solution that @Will posted in the comments from a similar question. Copy/pasting with some modifications from that question: add_action( ‘enqueue_block_assets’, ‘myplugin_enqueue_if_block_is_present’ ); // Can only be loaded in the footer // add_action( ‘wp_enqueue_scripts’, ‘myplugin_enqueue_if_block_is_present’ ); // Can be loaded in … Read more

gutenberg block – how to force update after attribute changed?

In this instance, you are treating the asynchronous jQuery AJAX call as a synchronous function, resulting in getStoriesList() consistently returning undefined as the function returns immediately after dispatching the HTTP request; trying to access response.status should be consistently throwing ReferenceError: response is not defined. In almost all cases it is more ideal to access data … Read more

Activate Gutenberg in category-descriptions

This isn’t possible at the moment, Gutenberg is a post editor that relies on REST API endpoints, it’s not an arbitrary content area editor as TinyMCE is. Given some modification though it could be made to work with a custom data model and be a replacement, but it’s not a trivial task, and what’s involved … Read more

Blocks: set a default value for a TextControl

Try setting the default value in your attributes instead of on the TextControl. registerBlockType( ‘cgb/a11ytable’, { title: ‘Accessible Table’, icon: ‘screenoptions’, category: ‘common’, attributes: { numCols: { type: ‘number’, default: 2 // Added default value } }, edit: (props) => { const { attributes: { numCols }, className, setAttributes } = props; return [ el( … Read more

Proper, exhaustive documentation for wp.editor etc

I have gone through the implementation of all Gutenberg core blocks in start, so now if I have to know how to use something then I first find the closest core component which is implementing that and then looks at the documentation of that particular block via https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src This process is solving problems for me … Read more