Adding a variation
How to ship a new variation under is-style-{slug} for core/image or core/gallery.
1. Pick a slug + name
Section titled “1. Pick a slug + name”Slug: lowercase, hyphenated, must produce a unique is-style-{slug} class. Avoid collisions with existing entries in includes/definitions/{block}-style-variations.php.
Label: short, translatable, surfaced in the block-styles picker.
2. Write the CSS
Section titled “2. Write the CSS”Create styles/{block}-variations/{slug}.css (one file per variation).
/** * Image variation: {Name} * * {What it does, one sentence. Why it exists.} * * @package PostFormatsBlockThemes * @since 2.1.0 */
.wp-block-image.is-style-{slug} { /* layout / decoration */}
.wp-block-image.is-style-{slug} img { /* image rules */}
@media (prefers-reduced-motion: no-preference) { /* any transitions or transforms go here */}
@media print { /* flatten decorative effects */}Quality gates (the brief’s Section 8)
Section titled “Quality gates (the brief’s Section 8)”Before merging, verify:
- Token check. No bare hex colors, no bare
pxvalues (except 1px borders), no bareremvalues outsidevar()fallbacks. Wrap any magic value invar(--pfbt-{slug}-{property}, fallback)so themes can override. - Reduced-motion check. Every
transition:andtransform:lives inside@media (prefers-reduced-motion: no-preference). - Specificity check. No
!important. Specificity wins via.wp-block-image.is-style-{slug}(one chained class beats core’s plain.wp-block-image). - Print check. A
@media printrule flattens shadows, rotations, decorative borders. - RTL check. Logical properties only (
inline-start,inline-end,padding-inline-*). Noleft/right/padding-left/padding-right. - Single-file check. All variation CSS in one file. No imports from other variation files.
- i18n check. Label uses
__()with the plugin text domain.
3. Add the definition entry
Section titled “3. Add the definition entry”Open includes/definitions/{block}-style-variations.php and append:
array( 'slug' => 'my-new-variation', 'label' => __( 'My New Variation', 'post-formats-for-block-themes' ), 'style_path' => 'styles/image-variations/my-new-variation.css', 'description' => __( 'One-sentence description for docs.', 'post-formats-for-block-themes' ),),style_handle is computed automatically (pfbt-{block}-variation-{slug}); supply your own if you want to share a stylesheet across variations.
For Interactivity-API variations, add view_module and view_module_id:
array( 'slug' => 'my-interactive', 'label' => __( 'My Interactive', 'post-formats-for-block-themes' ), 'style_path' => 'styles/gallery-variations/my-interactive.css', 'view_module' => 'blocks/gallery-variations/my-interactive/view.js', 'view_module_id' => 'post-formats/my-interactive',),4. Add the third-party hook (optional)
Section titled “4. Add the third-party hook (optional)”Themes and other plugins can register variations without forking PFBT. Use the registry’s filters:
add_filter( 'pfbt_image_style_variations', function ( $defs ) { $defs[] = array( 'slug' => 'my-theme-tape', 'label' => __( 'Tape Frame', 'my-theme' ), 'style_path' => 'styles/image-variations/tape.css', // `style_path` here is a path under PFBT_PLUGIN_URL; for theme- // shipped variations, use a fully qualified URL via a custom // `style_handle` you wp_register_style yourself. ); return $defs;} );5. Test
Section titled “5. Test”Locally:
composer phpcs # WPCS lintcomposer phpstan # static analysiscomposer phpunit -- --filter Test_Block_Style_RegistryIn the editor:
- Enable the feature flag (
add_filter( 'pfbt_feature_image_gallery_styles', '__return_true' );in a mu-plugin). - Insert an Image (or Gallery) block on a fresh post.
- Sidebar → Styles → confirm your variation appears with the correct label.
- Click it → confirm the editor preview updates.
- Save → view on front-end → hard-refresh.
- Open DevTools → Network tab → filter for your stylesheet handle → confirm it loads only when the variation is in use.
- Toggle dark mode (or switch to Twenty Twenty-Five) → confirm tokens fall back gracefully.
6. Update the docs
Section titled “6. Update the docs”Add an entry to docs/BLOCK-STYLE-VARIATIONS.md so authors know the variation exists and when to use it.