Skip to content

Commit

Permalink
Check for existing data-id attribute on the image block content
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Oct 27, 2021
1 parent 9752eec commit 585fc17
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* Server-side rendering of the `core/image` block.
*
* @package gutenberg
*/

/**
* Renders the `core/image` block on server.
*
Expand All @@ -10,7 +16,9 @@ function render_block_core_image( $attributes, $content ) {
if ( $attributes['id'] ) {
// Add the data-id="$id" attribute to the img element to retain backwards compatibility.
$data_id_attribute = 'data-id="' . esc_attr( $attributes['id'] ) . '"';
$content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
if ( ! strpos( $content, $data_id_attribute ) ) {
$content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
}
}
return $content;
}
Expand Down

0 comments on commit 585fc17

Please sign in to comment.