The get_block_editor_settings() WordPress PHP function returns the contextualized block editor settings for a selected editor context.
Usage
$settings = get_block_editor_settings($custom_settings, $block_editor_context);
Parameters
- $custom_settings (array): Required. Custom settings to use with the given editor type.
- $block_editor_context (WP_Block_Editor_Context): Required. The current block editor context.
More information
See WordPress Developer Resources: get_block_editor_settings()
Examples
Customize block editor settings for a specific post type
In this example, we customize the block editor settings for a specific post type, adding a custom color palette.
function mytheme_editor_settings($settings, $context) { if ($context->post_type === 'my_post_type') { $settings['colorPalette'] = array( array( 'name' => 'My theme primary color', 'slug' => 'mytheme-primary', 'color' => '#123456', ), ); } return $settings; } add_filter('block_editor_settings', 'mytheme_editor_settings', 10, 2);
Enable custom font sizes for a specific post type
In this example, we enable custom font sizes for a specific post type.
function mytheme_enable_custom_font_sizes($settings, $context) { if ($context->post_type === 'my_post_type') { $settings['enableCustomFontSizes'] = true; } return $settings; } add_filter('block_editor_settings', 'mytheme_enable_custom_font_sizes', 10, 2);
Disable custom colors for a specific post type
In this example, we disable custom colors for a specific post type.
function mytheme_disable_custom_colors($settings, $context) { if ($context->post_type === 'my_post_type') { $settings['disableCustomColors'] = true; } return $settings; } add_filter('block_editor_settings', 'mytheme_disable_custom_colors', 10, 2);
Set custom image dimensions for a specific post type
In this example, we set custom image dimensions for a specific post type.
function mytheme_custom_image_dimensions($settings, $context) { if ($context->post_type === 'my_post_type') { $settings['imageDimensions'] = array( 'mytheme_thumbnail' => array( 'width' => 150, 'height' => 150, ), ); } return $settings; } add_filter('block_editor_settings', 'mytheme_custom_image_dimensions', 10, 2);
Set a custom style for a specific post type
In this example, we set a custom style for a specific post type.
function mytheme_custom_styles($settings, $context) { if ($context->post_type === 'my_post_type') { $settings['styles'][] = array( 'css' => '.my-post-type .wp-block { background-color: #f0f0f0; }', ); } return $settings; } add_filter('block_editor_settings', 'mytheme_custom_styles', 10, 2);