Display multiple images in a rich gallery.
- Name:
core/gallery - Category: media
- API Version: 3
- Block Type: Hybrid (static save + server enhancements)
- Keywords:
images,photos
Block Relationships
Allowed inner blocks:
– core/image
Attributes
Defined via the attributes property in block.json.
| Attribute | Type | Default | Description |
|---|---|---|---|
images |
array |
[] |
Source: query. Selector: .blocks-gallery-item |
ids |
array |
[] |
— |
dynamicContent |
object |
— | — |
navigationButtonType |
string |
"icon" |
Enum: icon, text, both |
shortCodeTransforms |
array |
[] |
— |
columns |
number |
— | — |
caption |
rich-text |
— | Source: rich-text. Selector: .blocks-gallery-caption. Role: content |
imageCrop |
boolean |
true |
— |
randomOrder |
boolean |
false |
— |
fixedHeight |
boolean |
true |
— |
linkTarget |
string |
— | — |
linkTo |
string |
— | — |
sizeSlug |
string |
"large" |
— |
allowResize |
boolean |
false |
— |
aspectRatio |
string |
"auto" |
— |
Supports
Defined via the supports property in block.json.
anchor:truealign:truehtml:falseunits:"px","em","rem","vh","vw"spacing:margin:truepadding:trueblockGap:{"sides":["horizontal","vertical"],"__experimentalDefault":"var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )"}
color:text:falsebackground:truegradients:true
layout:allowSwitching:falseallowInheriting:falseallowEditing:falsedefault:{"type":"flex"}
interactivity:clientNavigation:true
listView:true
Context
Defined via the usesContext and providesContext properties in block.json.
Uses context:
galleryIdpostIdpostType
Provides context:
allowResizeattributeallowResizeimageCropattributeimageCropfixedHeightattributefixedHeightnavigationButtonTypeattributenavigationButtonType
Block Markup
This is a hybrid block. It saves static markup that the server may enhance during rendering.
<!-- wp:gallery {"linkTo":"none","className":"columns-2"} -->
<figure
class="wp-block-gallery has-nested-images columns-default is-cropped columns-2"
>
<!-- wp:image {"id":1421,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large">
<img
src="https://sergioestevaofolio.files.wordpress.com/2016/09/cropped-img_9054-1.jpg?w=190"
alt="Image gallery image"
class="wp-image-1421"
/>
</figure>
<!-- /wp:image -->
<!-- wp:image {"id":1440,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large">
<img
src="https://sergioestevaofolio.files.wordpress.com/2017/09/cropped-l1001498-1.jpg?w=580"
alt="Image gallery image"
class="wp-image-1440"
/>
</figure>
<!-- /wp:image -->
</figure>
<!-- /wp:gallery -->
Source
- block.json (reference)
- Source directory — browse
edit.js,save.js,index.php, and more.