The block_editor_settings WordPress PHP filter allows you to modify the default settings passed to the block editor.
Usage
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);
function my_custom_block_editor_settings($editor_settings, $post) {
// your custom code here
return $editor_settings;
}
Parameters
$editor_settings(array) – Default editor settings.$post(WP_Post) – Post being edited.
More information
See WordPress Developer Resources: block_editor_settings
Examples
Change Block Editor Color Palette
To modify the color palette in the block editor:
function my_custom_block_editor_settings($editor_settings, $post) {
$editor_settings['colorPalette'] = array(
array(
'name' => 'Blue',
'slug' => 'blue',
'color' => '#0073aa',
),
array(
'name' => 'Red',
'slug' => 'red',
'color' => '#e74c3c',
),
);
return $editor_settings;
}
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);
Disable Custom Font Sizes
To disable custom font sizes in the block editor:
function my_custom_block_editor_settings($editor_settings, $post) {
$editor_settings['disableCustomFontSizes'] = true;
return $editor_settings;
}
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);
Set Image Sizes
To define custom image sizes available in the block editor:
function my_custom_block_editor_settings($editor_settings, $post) {
$editor_settings['imageSizes'] = array(
array(
'slug' => 'custom-size',
'name' => 'Custom Size',
),
);
return $editor_settings;
}
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);
Disable Custom Colors
To disable custom colors in the block editor:
function my_custom_block_editor_settings($editor_settings, $post) {
$editor_settings['disableCustomColors'] = true;
return $editor_settings;
}
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);
Set Custom Gradient Presets
To set custom gradient presets in the block editor:
function my_custom_block_editor_settings($editor_settings, $post) {
$editor_settings['gradients'] = array(
array(
'name' => 'Vivid Blue to Green',
'gradient' => 'linear-gradient(135deg, #0073aa 0%, #08a539 100%)',
'slug' => 'vivid-blue-to-green',
),
);
return $editor_settings;
}
add_filter('block_editor_settings', 'my_custom_block_editor_settings', 10, 2);