·1 min de lecture
Gutenberg : override core blocks rendering
Auteur(s) de l'article
Suddenly, you find yourself in the need of implementing this neat and amazing Js gallery plugin which will make your website look so cool!
Creating your own gallery block seems like a tedious task, and the existing
core/galleryworks already perfectly in the backend. So let's simply change the way the gallery block is rendering on your website, so you can have you kick-ass look without having to worry about the editing experience, which has already been taken care of!
The easiest way to achieve this, is to consider the gallery as a Dynamic block and re-declare its render through PHP:
- Declare the block in you chosen php file using the
inithook (typically inside of your them's
- Use the exact same block name as the one you want to override. (here
- Only use the
render_callbackkey to target you own function
...waiting for Gist...
And ta-da! Nothing more is required, the gallery plugin still works the same in the backend, and you are free to experiment all you like with your new render.
This works for all core gutenberg blocks, which means you can take advantage of the great blocks already developped, and arrange their output as you wish. If you want some nice documentation about the core gutenberg blocks, I recommend Gutenberg Blocks: A Complete List & How to Use Them
Mise à jour le: 19 January 2022