/blocks

DescriptionDescription

This filter is called when the card builder retrieves available blocks and when a card renders custom blocks.

It allows to add your own blocks in the card builder in order to output custom content with your own markup and logic.

ArgumentsArguments

ArgumentTypeDescription
$blocks arrayHolds custom block definitions

ExampleExample

PHP
functions.php
function prefix_register_block( $blocks ) {
	
	// 'my_block' corresponds to the block slug.
	$blocks['my_block'] = [
		'name' => __( 'My Block', 'text-domain' ),
		'render_callback' => 'prefix_my_block_render',
	];

	return $blocks;
	
}

add_filter( 'wp_grid_builder/blocks', 'prefix_register_block', 10, 1 );

// The render callback function allows to output content in cards.
function prefix_my_block_render() {

	// Get current post, term, or user object.
	$post = wpgb_get_post();

	// Output the post title.
	echo '<h3>' . esc_html( $post->post_title ) . '</h3>';

}