Using WordPress ‘block_type_metadata_settings’ PHP filter

The block_type_metadata_settings WordPress PHP filter allows you to modify the settings determined from the block type metadata.

Usage

add_filter('block_type_metadata_settings', 'your_custom_function', 10, 2);
function your_custom_function($settings, $metadata) {
    // Your custom code here
    return $settings;
}

Parameters

  • $settings (array): Array of determined settings for registering a block type.
  • $metadata (array): Metadata provided for registering a block type.

More information

See WordPress Developer Resources: block_type_metadata_settings

Examples

Modify block title

Update the block title from the metadata before registering the block.

add_filter('block_type_metadata_settings', 'modify_block_title', 10, 2);
function modify_block_title($settings, $metadata) {
    $settings['title'] = 'New Block Title';
    return $settings;
}

Add custom category

Add a custom category to the block type settings.

add_filter('block_type_metadata_settings', 'add_custom_category', 10, 2);
function add_custom_category($settings, $metadata) {
    $settings['category'] = 'custom-category';
    return $settings;
}

Modify block attributes

Add or update attributes for the block type.

add_filter('block_type_metadata_settings', 'modify_block_attributes', 10, 2);
function modify_block_attributes($settings, $metadata) {
    $settings['attributes']['customAttribute'] = array(
        'type' => 'string',
        'default' => 'Hello World'
    );
    return $settings;
}

Set custom icon

Set a custom icon for the block type.

add_filter('block_type_metadata_settings', 'set_custom_icon', 10, 2);
function set_custom_icon($settings, $metadata) {
    $settings['icon'] = 'dashicons-admin-customizer';
    return $settings;
}

Change block style variation

Modify the block style variation settings.

add_filter('block_type_metadata_settings', 'change_block_style_variation', 10, 2);
function change_block_style_variation($settings, $metadata) {
    $settings['styles'][] = array(
        'name' => 'new-style',
        'label' => 'New Style Variation'
    );
    return $settings;
}