Back to all posts

Create a Custom WordPress Block


Creating custom blocks in WordPress unlocks the full power of the Gutenberg editor, allowing you to design reusable content elements tailored to your website’s needs. Here’s a step-by-step guide to building your first WordPress block.


Step 1: Scaffold Your Block Plugin

The easiest and most modern approach is to use the official @wordpress/create-block package. Open your terminal, navigate to your desired directory, and run:

npx @wordpress/create-block@latest my-custom-block --variant=dynamic
cd my-custom-block

This command generates a new plugin folder (my-custom-block) with all the files you need to start customizing your block. The --variant=dynamic flag sets up a block that is rendered via PHP, giving you more flexibility for dynamic content

Step 2: Activate the Plugin

  • Go to your WordPress admin dashboard.
  • Navigate to Plugins.
  • Find your new plugin (e.g., “My Custom Block”) and activate it

Step 3: Insert and Test Your Block

  • Create or edit a post/page in the Block Editor.
  • Search for your block by its name (e.g., “My Custom Block”).
  • Insert it and confirm it displays as expected2.

Check this video for more detailed explantion