GCBGutenberg
Control Blocks
v1.3.3
Buy

Accordion

Rows that open and close, each with a title and any blocks inside. For FAQs, specs and long lists.

An accordion for FAQs, specs and other long lists. Each row is a block of its own: a title your client types on the canvas, and any blocks underneath it. Two settings choose whether one row is open at a time and whether the first starts open.

The Accordion example in the editor: each row is its own block, with its title and any blocks beneath it.
The Accordion example in the editor: each row is its own block, with its title and any blocks beneath it.

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

  • accordion/ The accordion and its two settings.
  • accordion-item/ One row: a title and any blocks beneath it.

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

A <Repeater> in the accordion's template marks where the rows go and sets how few and how many there can be. Every row is real content in the page, so search engines and screen readers get all of it.

accordion/render.php
<Repeater  allowedBlocks='["gcb/accordion-item"]'  addButtonLabel="Add row"  min="1"  max="40"  editLayout="accordion"/>

Its fields, from block.fields.json:

FieldType
One open at a timetoggle
First row open to starttoggle

view.js is about 2 KB of plain JavaScript. With no script, every row is open.

Use it

  1. Unzip the download.
  2. Copy accordion/ and accordion-item/ into your theme's blocks/ folder.
  3. 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.

Build anything in the block editor

Every licence includes all features and a year of updates and support.

Buy GCB from $8.25 a month See pricing