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



wp_render_elements_class_name › WordPress Function

Since6.6.0
Deprecatedn/a
wp_render_elements_class_name ( $block_content, $block )
Parameters: (2)
  • (string) $block_content Rendered block content.
    Required: Yes
  • (array) $block Block object.
    Required: Yes
See:
Returns:
  • (string) Filtered block content.
Defined at:
Codex:

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



Source

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();
}