wp_render_elements_class_name()WP 6.6.0

Ensure the elements block support class name generated, and added to block attributes, in the render_block_data gets applied to the block's markup.

No Hooks.

Return

String. Filtered block content.

Usage

wp_render_elements_class_name( $block_content, $block );
$block_content(string) (required)
Rendered block content.
$block(array) (required)
Block object.

Notes

Changelog

Since 6.6.0 Introduced.

wp_render_elements_class_name() code WP 6.8

function wp_render_elements_class_name( $block_content, $block ) {
	$class_string = $block['attrs']['className'] ?? '';
	preg_match( '/\bwp-elements-\S+\b/', $class_string, $matches );

	if ( empty( $matches ) ) {
		return $block_content;
	}

	$tags = new WP_HTML_Tag_Processor( $block_content );

	if ( $tags->next_tag() ) {
		$tags->add_class( $matches[0] );
	}

	return $tags->get_updated_html();
}