render_block_core_accordion()WP 6.9.0

Server-side rendering of the core/accordion block.

No Hooks.

Returns

String. Returns the updated markup.

Usage

render_block_core_accordion( $attributes, $content );
$attributes(array) (required)
The block attributes.
$content(string) (required)
The block content.

Notes

  • Package: WordPress

Changelog

Since 6.9.0 Introduced.

render_block_core_accordion() code WP 6.9.1

function render_block_core_accordion( $attributes, $content ) {
	if ( ! $content ) {
		return $content;
	}

	$p         = new WP_HTML_Tag_Processor( $content );
	$autoclose = $attributes['autoclose'] ? 'true' : 'false';

	if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion' ) ) ) {
		$p->set_attribute( 'data-wp-interactive', 'core/accordion' );
		$p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "accordionItems": [] }' );

		// Only modify content if directives have been set.
		$content = $p->get_updated_html();
	}

	return $content;
}