Skip to content
pinegrow.com
Docs menuWordPress

Creating your first block

Let’s build a custom block together.

On this page

We will start with a HTML landing page implemented with Bootstrap 5. The steps described in this guide assume that the theme export is already set up.

Download and set up the project

Would you like to follow the steps described in this guide? Download the project and set up the theme export.

Decide which element to convert into a block

The page has an About Me section that would work great as a block:

The story section of the Fizz Lab home page as it shows in the Pinegrow page view, with no editor panels: an ingredients photo, the Nothing weird. Ever. heading, a paragraph and four check items, a good candidate for a custom block.

Add the Block action

To create a new block type, select the About Me <section> HTML element. In the Properties panel, open the WordPress tab (the WordPress icon), click + next to WordPress Actions and choose Blocks Smart Actions › Block.

The story section selected, with the WordPress actions tab open and the menu of the + next to WordPress Actions (marked by a callout) on Blocks Smart Actions, offering Block and Block Condition; Block is boxed, with its tooltip Create a custom Gutenberg block.

Block action settings are now shown in the WordPress panel:

The Fizz Hero section of page.html selected, with the Block action in the WordPress panel: Unique Id fizz-hero, Title Fizz Hero, Description, Icon star-filled, Category Custom, Category name Fizz Lab and Auto create, and a callout on the + next to WORDPRESS ACTIONS.

Give the block a unique id

Each block needs an id. In WordPress the whole id consists of the namespace (theme or plugin slug, for example), followed by the block id, for example mytheme/aboutme.

On Block action, we just enter the main id, in our case aboutme. Pinegrow will automatically prepend the theme / plugin slug as the namespace during export.

The Block action of the story section with Unique Id ingredients; Title, Description and Icon are still empty and Category shows text.

Describe the block

Name, description and icon help users find and understand the function of the block.

The Block action of the story section with Unique Id ingredients, Title Ingredients, Description Photo, heading and ingredient checks, and Icon carrot.

Icon can be one of built-in WordPress dashicons, or SVG image code. We will use the icon named id.

Category places the block into one of predefined WordPress block categories or into a custom category.

Regular and dynamic blocks

Let’s take a quick peek into the More options section (click More options at the bottom of the Block action), without having to change any settings there.

The main setting there is Block type that selects the way how the block is implemented.

The Block type list under More options of the Block action, with a callout on the More options toggle: Auto (use project setting) checked, Regular JavaScript/React block, Dynamic PHP block, Hybrid (React in the editor, PHP on the front-end) and ACF.

There are two types of native WordPress blocks that don’t require any plugins: regular and dynamic.

  • Regular blocks are implemented in JavaScript and offer the best editing experience and performance. But, such blocks can not use WordPress actions such as Show posts.
  • Dynamic blocks are implemented in PHP and render their content on the server, every time they are displayed. They can use any WordPress action and always display up-to-date information. The editing process has delays due to server-side rendering.

ACF blocks are implemented as Advanced Custom Fields PRO Blocks. They offer a mix of browser-side and server-side rendering. 

Learn more about the difference between regular, dynamic and ACF blocks.

We will leave the Block type setting on auto in order to generate a regular JavaScript block.

Export the theme

Export the theme with WordPress › Export the theme (CMD + M)…

The WordPress menu open over the Fizz-Lab project with Export the theme (Cmd M) highlighted at the top.

…and reload the Block editor.

Use the block in the block editor

Our About me block is listed in the block library from where we can drag it to the content:

WordPress block inserter with the About me block being dragged onto the page, beside the About Me section.

But, the block is not yet editable. We can’t change its content and it has no control fields in the sidebar:

Block editor Front Page with the About Me block, with callouts saying its content is not editable and it has no sidebar settings.

Next step

Next step: Adding editable attributes and controls.