A plugin to add a custom block to the WordPress block editor.
This plugin demonstrates how to create a custom block for the WordPress block editor (Gutenberg) using React and the WordPress Scripts package.
- WordPress installation
- Node.js and npm installed
-
Clone this repository or download the zip file and extract it into your WordPress
wp-content/plugins
directory. -
Navigate to the plugin directory.
cd wp-content/plugins/my-plugin
-
Install the necessary npm packages.
npm install
-
Build the project.
npx wp-scripts build
- Activate the plugin from the WordPress admin dashboard under "Plugins".
- Go to the WordPress editor (add or edit a post/page).
- Click the "+" button to add a new block.
- Search for "My Block" (or the title you gave your block).
- Add the block to the post/page and verify that it works as expected.
my-plugin/
├── build/
│ ├── index.asset.php
│ └── index.js
├── node_modules/
├── src/
│ └── index.js
├── my-plugin.php
├── package.json
├── package-lock.json
Installing Dependencies
npm install @wordpress/scripts --save-dev
Building the Project
npx wp-scripts build
Clearing npm Cache (if needed)
npm cache clean --force
This project is licensed under the MIT License. See the LICENSE file for details.