The block_has_support() WordPress PHP function is used to check whether a given block type supports a certain feature.
Usage
To use the block_has_support() function, pass the block type and the feature to check as parameters. Optionally, a default value can be provided as a fallback if the feature support isn’t confirmed. Here’s a custom example:
$support = block_has_support( 'core/paragraph', array( 'align' ), false );
In this example, we’re checking if the ‘core/paragraph’ block supports alignment. If it doesn’t, the function will return false
.
Parameters
- $block_type (WP_Block_Type – Required): The block type you’re checking for support.
- $feature (array – Required): The specific feature you’re checking support for.
- $default_value (mixed – Optional): Fallback value for feature support. The default value is
false
.
More information
See WordPress Developer Resources: block_has_support()
The function was implemented in WordPress 5.6. It’s not deprecated, and it’s located in the block-supports directory.
Examples
Checking for Color Support
This example checks if the ‘core/paragraph’ block supports color settings.
$support = block_has_support( 'core/paragraph', array( 'color' ) );
Checking for Custom Font Size
This checks if the ‘core/heading’ block supports custom font size.
$support = block_has_support( 'core/heading', array( 'fontSize' ) );
Checking for Spacing Support
This verifies if the ‘core/columns’ block supports spacing between columns.
$support = block_has_support( 'core/columns', array( 'spacing' ) );
Checking for Typography Support
This checks if the ‘core/quote’ block supports typography settings.
$support = block_has_support( 'core/quote', array( 'typography' ) );
Checking for Link Color Support
This verifies if the ‘core/button’ block supports custom link color.
$support = block_has_support( 'core/button', array( 'linkColor' ) );
In all examples, $support
will be true
if the block supports the feature, or false
if it doesn’t.