Using WordPress ‘get_block_wrapper_attributes()’ PHP function

The get_block_wrapper_attributes() WordPress PHP function generates a string of attributes by applying all of the features that the current block being rendered supports.

Usage

$wrapper_attributes = get_block_wrapper_attributes(array('class' => 'custom-class', 'style' => 'color: #333'));

Parameters

  • $extra_attributes (array) – Optional. Array of extra attributes to render on the block wrapper. Default: array()

More information

See WordPress Developer Resources: get_block_wrapper_attributes()

Examples

Basic usage

This example generates a string of attributes for the block wrapper.

$wrapper_attributes = get_block_wrapper_attributes();

Adding a custom class

This example adds a custom CSS class to the block wrapper.

$wrapper_attributes = get_block_wrapper_attributes(array('class' => 'my-custom-class'));

Adding inline styles

This example adds inline CSS styles to the block wrapper.

$wrapper_attributes = get_block_wrapper_attributes(array('style' => 'background-color: #f0f0f0; padding: 1em;'));

Adding custom class and inline styles

This example adds a custom CSS class and inline CSS styles to the block wrapper.

$wrapper_attributes = get_block_wrapper_attributes(array('class' => 'my-custom-class', 'style' => 'background-color: #f0f0f0; padding: 1em;'));

Adding a custom data attribute

This example adds a custom data attribute to the block wrapper.

$wrapper_attributes = get_block_wrapper_attributes(array('data-custom-attribute' => 'custom-value'));