Gallery


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.

Context

Defined via the usesContext and providesContext properties in block.json.

Uses context:

  • galleryId
  • postId
  • postType

Provides context:

  • allowResize attribute allowResize
  • imageCrop attribute imageCrop
  • fixedHeight attribute fixedHeight
  • navigationButtonType attribute navigationButtonType

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