\WP_Stager_Integration\Component::render_block_component(callable $render_callback, array $extra_attributes = array()): string
\WP_Stager_Integration\Component::render_block_component(callable $render_callback, array $extra_attributes = array()): stringDescription
Render a component for a block with wrapper attributes.
This method captures the output of a component rendering method and wraps it in a block wrapper div with the appropriate attributes.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$render_callback | callable | The callback function that renders the component (e.g., array( __CLASS__, 'render_event_name' )). |
$extra_attributes | array | (Optional) Extra attributes to add to the block wrapper. |
Returns:
string The HTML output with block wrapper.
Information
| File | class-component.php line 834 |
|---|
Full Code
/**
* Render a component for a block with wrapper attributes.
*
* This method captures the output of a component rendering method and wraps it
* in a block wrapper div with the appropriate attributes.
*
* @param callable $render_callback The callback function that renders the component (e.g., array( __CLASS__, 'render_event_name' )).
* @param array $extra_attributes (Optional) Extra attributes to add to the block wrapper.
*
* @return string The HTML output with block wrapper.
*/
public static function render_block_component( $render_callback, $extra_attributes = array() ) {
// Type casting
$render_callback = $render_callback;
$extra_attributes = (array) $extra_attributes;
// Start output buffering
ob_start();
// Call the render callback
if ( is_callable( $render_callback ) ) {
call_user_func( $render_callback );
}
// Get the component output
$component_output = ob_get_clean();
// Get block wrapper attributes
$wrapper_attributes = get_block_wrapper_attributes( $extra_attributes );
// Build the HTML with wrapper
$html = '<div';
if ( $wrapper_attributes ) {
$html .= ' ' . $wrapper_attributes;
}
$html .= '>' . $component_output . '</div>';
return $html;
}💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration
🎁 Limited offer: Use code WELCOME26 to get your first month for free!

