A carousel your client edits slide by slide, on the canvas. Each slide is a block of its own and takes any blocks inside it: a picture, words, or a block of yours. On the page it is a scroll-snap track with arrows and dots, and it swipes on a phone.
Download example A zip of block folders for your theme. Needs GCB 1.3.1 or later, and nothing else.
What's in the download
carousel/The carousel. Its fields set how many slides show across, the gap, arrows, dots and autoplay.slide/One slide. Any blocks go inside.
Each folder is an ordinary GCB block: block.json, block.fields.json and render.php, plus a style.css and a view.js where it needs them. There is no build step and no library.
How it's built
The carousel's template marks where the slides go with a <Repeater>. That one marker holds every rule about them: which block a slide is, the label on the Add button, and the fewest and most slides a page may have. WordPress won't save a page outside those limits.
<Repeater allowedBlocks='["gcb/slide"]' addButtonLabel="Add slide" min="1" max="24" editLayout="carousel"/>Its fields, from block.fields.json:
| Field | Type |
|---|---|
| Slides across | range |
| Gap | range |
| Arrows | toggle |
| Dots | toggle |
| Autoplay | range |
view.js is about 4 KB of plain JavaScript with no library behind it. With no script, every slide shows, one after another.
Use it
- Unzip the download.
- Copy
carousel/andslide/into your theme'sblocks/folder. - Reload the block editor. The block is in the inserter.
That's all of it. You don't register the block: there's no register_block_type() call and nothing to add to functions.php. GCB registers every folder in your theme's blocks/ folder by itself.
It is your block now. Change the markup, the fields or the script to suit the design. The docs cover every field type and marker used here.
More examples: all examples, or download them together as the GCB Kit.