Create a new Gutenberg block following WordPress best practices.
Ask the User For
- •Block name (e.g., "accordion", "testimonial-slider")
- •Block category (e.g., "design", "widgets", "text", "media")
- •Needs frontend JavaScript? (Yes/No)
- •Needs dynamic rendering (PHP)? (Yes/No)
What Gets Created
- •Block directory:
src/blocks/[block-name]/ - •
block.jsonwith proper metadata and attributes - •
index.jsto register the block - •
edit.jswith editor controls - •
save.jswith frontend markup - •
style.scssfor frontend styles - •
editor.scssfor editor-only styles - •
frontend.js(if needed for interactivity) - •
render.php(if dynamic rendering needed)
Critical Patterns to Follow
ALWAYS use these in edit.js:
- •
useBlockProps()for block wrapper - •
useInnerBlocksProps()for nested blocks (NOT plain<InnerBlocks />) - •Declarative styling (NO
useEffectfor styles)
ALWAYS include in block.json:
- •Comprehensive
supportsfor FSE compatibility - •
exampleproperty for pattern library - •WordPress presets (no hardcoded colors/spacing)
Color controls:
- •Use
ColorGradientSettingsDropdown(NOTPanelColorSettings) - •Place in
<InspectorControls group="color"> - •Require
clientIdparameter in edit function
After Creation
Block will be auto-detected by webpack - no need to modify src/index.js.
If dynamic rendering is used, add PHP registration in includes/class-plugin.php.
Build and Test
bash
npm run build
Test in both editor and frontend.
Reference
See BEST-PRACTICES-SUMMARY.md for complete patterns.