Skip to content
pinegrow.com
Docs menuWordPress

Inner blocks: blocks within blocks

Create an area where sub-blocks can be inserted into the block.

On this page

Blocks can contain other blocks. In WordPress, sub-blocks are called inner blocks.

Each block can have only one inner blocks area. Multiple inner blocks areas are not supported in WordPress.

We just need to add Block Inner Content action to the element that should contain inner blocks.

WordPress Actions for a Row div with the Block Inner Content action in the list, with a callout to create an inner blocks area.

For example, our About me block could have a content area where user can freely insert one or more blocks.

But let’s do something more interesting.

Create sub-blocks

Block Inner Content action lets us limit what kind of blocks can be inserted into the area. In addition, we can also define a new block type, tailor made for the inner content area.

Our HTML project has a div.row that contains counters, implemented as Bootstrap columns.

Select the div.row and add Block Inner Content action.

About Me section in Pinegrow with the div.row selected, the navigator showing the counter columns, and a callout that the row contains the counters.

Here, we don’t want just any kind of block to be added here. We will only allow Counter blocks by entering counter into the Allowed Block Types field. counter is the block id of the custom block we will create below.

Block Inner Content settings with Allowed block types set to counter, and a callout that only counter blocks are allowed.

Counter block

We also need to define the block type Counter.

Select the first counter element and add Block action with the id counter and title Counter.

WordPress Actions for a Column div with Unique Id counter, Title Counter, Description Describe your achievements and Icon award.

Make the number editable by selecting the <h4> element and adding Block Attributes action with the id number.

Block Attributes - Smart for an h4 with Block Attribute 1 set to attribute id number, Use as Content and Title Number.

Add another Block Attributes action to the <p> and set the id to label.

Block Attributes - Smart for an h3 with Block Attribute 1 set to attribute id label, Use as Content and Title Label.

Export the project and reload the Block editor.

We have to recover the block because the block structure changed. Just click on the Attempt Block Recovery button and WordPress will figure it out.

WordPress Front Page editor showing the surfing content with an unexpected or invalid content notice and Attempt Block Recovery button.

Edit, add and move counters

We can edit the numbers and labels of the counters. Each counter is a block.

WordPress block editor showing the I Love Surfing Huge Waves stat cards, with the 12m counter text being edited.

We now see an insertion point when the block is selected.

WordPress editor with the Add Counter button and an Add more counters callout beside the stat cards and Go surfing button.

Clicking on it will insert a new Counter block. Because only one block type is allowed, WordPress doesn’t ask us about what type of block we want to insert.

We can insert as many counters as we need.

Of course we can delete counters and reorder them with up and down controls.

WordPress editor with the 10+ Years of Experience counter selected and the Move down control highlighted in its block toolbar.

Note, as on the image above, the styling of our block in the Block editor can differ slightly from how they are styled on the front-end. In rare cases where this creates problems, we can use editor styling to fine-tune the styling in the editor.

For reference, this is how our block appears on the front-end:

Frontend page titled I Love Surfing Huge Waves with a surf photo and stat tiles showing 12m, 3, 8, 21 and 75m.

Recap of what we did so far

Learn more about the Block Inner Content action.

In just a few minutes we created a fully customizable block that we can reuse on this and other projects.

Our About me and Counter blocks are implemented as Regular JavaScript blocks because all their content is stored in attributes whose value is set at the time of editing the post.

Next step

Next, let’s create a dynamic PHP block that will display up-to-date information from the WordPress database.