Blocks
PressGang provides declarative Gutenberg block registration, keeping your block setup clean and your codebase shipshape. Define your blocks in config, and PressGang handles the registration, path resolution, and lifecycle hooks.
How It Works
Blocks are registered via config/blocks.php. Each entry points to a directory containing a block.json file. PressGang's Blocks configuration class:
Resolves the block path (checking the child theme first, then the parent theme).
Validates and reads the
block.jsonfile.Registers the block type with WordPress.
Invokes any
on_registercallback defined in the block's ACFrenderCallback.Fires a
pressgang_block_registered_{name}action for additional setup.
Directory Structure
Each block lives in its own directory under blocks/:
blocks/
hero/
block.json
hero.twig
testimonial/
block.json
testimonial.twigThe block.json file follows the standard WordPress block.json format.
Configuration
Simple Registration
List paths to block directories in config/blocks.php:
With Additional Arguments
Pass extra arguments for register_block_type() using an associative array:
Child/Parent Theme Resolution
PressGang automatically checks the child theme directory first when resolving block paths. This means you can override a parent theme's block by creating a block with the same path in your child theme. The resolved paths are cached for performance.
ACF Blocks
PressGang has first-class support for ACF blocks. When a block's block.json defines an ACF renderCallback, PressGang will:
Look for the class specified in
acf.renderCallback[0].If the class exists and has a static
on_register()method, call it with the block settings.
This allows blocks to perform one-time setup (like registering field groups) at registration time.
Example block.json
Hooks
pressgang_block_registered_{name}
action
Fired after a block is registered. Receives the block settings array.
The {name} placeholder is the block's name field from block.json (e.g. pressgang_block_registered_acf/hero).
Block Rendering Rules
Block rendering should be a pure function of block context — no side effects, no queries in the render path that aren't cached.
Keep block templates simple and focused.
Prefer Twig templates over inline PHP render callbacks.
For new UI elements, prefer blocks over shortcodes — they give editors a much better experience.
Last updated