wp-includes/blocks/gallery.php:309Renders the core/gallery block on the server.
$attributesarray$contentstring$blockarraystringfunction block_core_gallery_render( $attributes, $content, $block ) { static $global_styles = null; // In dynamic mode the gallery's images are resolved at render time instead of // being authored as inner blocks, so `save.js` persists at most the // gallery-level caption — a bare `<figcaption>`, or nothing when there is no // caption. Resolve the configured source to a list of attachments, render an // image block for each, and build the gallery `<figure>` wrapper from scratch. // The gap/randomOrder/lightbox post-processing below then runs over the // constructed markup unchanged. if ( ! empty( $attributes['dynamicContent'] ) ) { $attachment_ids = block_core_gallery_resolve_dynamic_source( $attributes['dynamicContent'], $block ); // Nothing resolved — no attachments, or an unrecognized source. Render // nothing rather than an empty gallery wrapper; a saved caption is // meaningless without images, so it is intentionally dropped too. if ( empty( $attachment_ids ) ) { return ''; } // The source query only fetched IDs (`fields => ids`), which skips // WP_Query's cache priming. Each image rendered below reads the // attachment post and its meta (via `wp_get_attachment_image()`, // `get_post()`, etc.), so warm the post and meta caches in a single pair // of queries up front instead of paying ~two queries per attachment. // Term cache is left cold: the render path doesn't read attachment terms. if ( count( $attachment_ids ) > 1 ) { _prime_post_caches( $attachment_ids, false, true ); } // Expose the gallery's provided context (plus galleryId/postId/postType) // to each image block, since these images are rendered outside the // gallery's real inner-block tree. $image_context = array_merge( is_array( $block->context ) ? $block->context : array(), array( 'allowResize' => $attributes['allowResize'] ?? false, 'imageCrop' => $attributes['imageCrop'] ?? true, 'fixedHeight' => $attributes['fixedHeight'] ?? true, 'navigationButtonType' => $attributes['navigationButtonType'] ?? 'icon', ) ); $images_markup = ''; foreach ( $attachment_ids as $attachment_id ) { $images_markup .= block_core_gallery_render_dynamic_image( $attachment_id, $attributes, $image_context ); } // Build the wrapper rather than parsing/splicing saved markup. // `get_block_wrapper_attributes()` supplies the block-support // classes/styles (align, color, border, spacing, anchor id); the layout // render filter adds the flex layout classes downstream — the same way a // static gallery's wrapper is composed (`useBlockProps.save()` plus that // filter). Only the gallery-specific classes are added explicitly, and // they mirror `save.js` (kept in sync deliberately — see that file). $gallery_classes = 'wp-block-gallery has-nested-images'; $gallery_classes .= isset( $attributes['columns'] ) ? ' columns-' . (int) $attributes['columns'] : ' columns-default'; if ( $attributes['imageCrop'] ?? true ) { $gallery_classes .= ' is-cropped'; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $gallery_classes ) ); // In dynamic mode `save.js` persists only the gallery-level caption, so // `$content` is the saved `<figcaption>` (or empty). Append it after the // resolved images — matching the static gallery's `{images}{caption}` // order — without parsing it. $content = sprintf( '<figure %s>%s%s</figure>', $wrapper_attributes, $images_markup, $content ); } // Adds a style tag for the --wp--style--unstable-gallery-gap var. // The Gallery block needs to recalculate Image block width based on // the current gap setting in order to maintain the number of flex columns // so a css var is added to allow this. $style_attr = is_array( $attributes['style'] ?? null ) ? $attributes['style'] : array(); if (Introduced in 6.0.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$block added.verified against sourcesrc/wp-includes/blocks/gallery.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.