wpseek.com
A WordPress-centric search engine for devs and theme authors



render_block_core_image › WordPress Function

Sincen/a
Deprecatedn/a
render_block_core_image ( $attributes, $content )
Parameters: (2)
  • (array) $attributes The block attributes.
    Required: Yes
  • (string) $content The block content.
    Required: Yes
Returns:
  • (string) Returns the block content with the data-id attribute added.
Defined at:
Codex:

Renders the `core/image` block on the server, adding a data-id attribute to the element if core/gallery has added on pre-render.



Source

function render_block_core_image( $attributes, $content ) {
	if ( isset( $attributes['data-id'] ) ) {
		// Add the data-id="$id" attribute to the img element
		// to provide backwards compatibility for the Gallery Block,
		// which now wraps Image Blocks within innerBlocks.
		// The data-id attribute is added in a core/gallery `render_block_data` hook.
		$data_id_attribute = 'data-id="' . esc_attr( $attributes['data-id'] ) . '"';
		if ( ! str_contains( $content, $data_id_attribute ) ) {
			$content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
		}
	}
	return $content;
}