Wypo Logo Header@2x
Blog / Developer / Gutenberg / Gutenberg: Modifying block supports

Gutenberg: Modifying block supports

Developer Gutenberg
Time to read : 3 minutes

Publication date: 26 June 2024

Modifying existing blocks in Gutenberg may seem complex, but with WordPress, there are various JavaScript functions for adjusting supports, styles, adding HTML classes, and more. In this article, we’ll show you how to disable certain block supports to make your site even more personalized.

Pour commencer, vous devez créer un fichier editor.js à la racine de votre thème. Ce fichier contiendra le code JavaScript nécessaire pour modifier les supports des blocs. Ensuite, vous devez inclure ce fichier dans votre thème en ajoutant le code suivant à votre fichier functions.php :

PHP

This code ensures that the editor.js file is loaded into the WordPress block editor, allowing you to modify existing blocks.

Deactivate existing block supports

You can disable support for each block by adding the following code to your editor.js file:

JS

This JavaScript script modifies block parameters to disable support for sizing properties (padding, margin and gap) for buttons (core/buttons for parent and core/button for sub-blocks).

Detailed code explanations

  1. Function disableBlockSupports: This function takes two arguments, settings and name. settings contains the block parameters, and name is the block name.
  2. Disabling Dimensions: If the block name is core/buttons, we disable the spacing support (spacing). If the block contains inner blocks (innerBlocks), we iterate through each inner block to also disable spacing for blocks of type core/button.
  3. Block Registration Filter: We add a filter to blocks.registerBlockType that applies our disableBlockSupports function whenever a block is registered. This ensures our modification is applied to all blocks of type core/buttons and core/button.

With these adjustments, you can customize Gutenberg block supports to better suit the needs of your WordPress site. Test these modifications to see how they can improve the appearance and functionality of your blocks!

Last 30 days : 1
Total : 232