render_block_core_image

函数
render_block_core_image ( $attributes, $content )
参数
  • (array) $attributes The block attributes.
    Required:
  • (string) $content The block content.
    Required:
返回值
  • (string) Returns the block content with the data-id attribute added.
定义位置
相关方法
render_block_core_fileregister_block_core_imagerender_block_core_page_listrender_block_core_coverrender_block_core_site_tagline
引入
-
弃用
-

render_block_core_image: 这个函数用来渲染WordPress中的图像块。图片块允许用户在他们的网站上添加图片: 这个函数负责生成图片块的HTML标记。

在服务器上渲染`core/image`区块。

如果 core/gallery 在预渲染时添加了一个 data-id 属性,就会在该元素上添加一个 data-id 属性。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常见问题

FAQs
查看更多 >