Hooks & Filters
All BF Blocks hooks are prefixed bf_blocks/. Use standard WordPress add_action() and add_filter() calls to hook in.
bf_blocks/before_renderFires before a block is rendered on the front end. Use to enqueue scripts/styles conditionally.
Parameters: string $block_slug, array $fields, array $block
bf_blocks/after_renderFires after a block renders. Output has already been sent — use for side effects like logging.
Parameters: string $block_slug, string $output
bf_blocks/field_valueModify a field's value before it is passed to the PHP template.
Parameters: mixed $value, string $field_key, string $block_slug
bf_blocks/register_field_typeAdd a custom field type class to the registry. Key = type slug, value = class name.
Parameters: array $types
bf_blocks/block_savedFires when a block definition is created or updated.
Parameters: int $block_id, array $block_data
bf_blocks/block_deletedFires after a block is deleted.
Parameters: int $block_id
bf_blocks/template_pathOverride the PHP template path for a specific block.
Parameters: string $path, string $block_slug
bf_blocks/allowed_blocksFilter the allowed block types for an Inner Blocks field.
Parameters: array $blocks, string $inner_blocks_field_key
Code Examples
Conditionally enqueue a stylesheet
add_action(
'bf_blocks/before_render',
function( string $slug, array $fields, array $block ): void {
if ( $slug === 'bf-blocks/testimonial' ) {
wp_enqueue_style(
'testimonial-block',
get_template_directory_uri() . '/css/testimonial.css'
);
}
},
10,
3
);Modify a field value before render
add_filter(
'bf_blocks/field_value',
function( mixed $value, string $key, string $slug ): mixed {
if ( $slug === 'bf-blocks/testimonial' && $key === 'author_name' ) {
return strtoupper( $value );
}
return $value;
},
10,
3
);