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

You appear to be a bot. Output may be restricted

Description

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

Usage

$string = render_block_core_image( $attributes, $content );

Parameters

$attributes
( array ) required – The block attributes.
$content
( string ) required – The block content.

Returns

string Returns the block content with the data-id attribute added.

Source

File name: wordpress/wp-includes/blocks/image.php


Lines:

1 to 14 of 14
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 ( false === strpos( $content, $data_id_attribute ) ) {
      $content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
    }
  }
  return $content;
}
 

 View on GitHub View on Trac