Using WordPress ‘get_default_block_editor_settings()’ PHP function

The get_default_block_editor_settings() WordPress PHP function returns the default block editor settings.

Usage

$default_settings = get_default_block_editor_settings();

Parameters

  • None

More information

See WordPress Developer Resources: get_default_block_editor_settings()

Examples

Display Default Block Editor Settings

This code retrieves and displays the default block editor settings.

$default_settings = get_default_block_editor_settings();
echo '<pre>';
print_r($default_settings);
echo '</pre>';

Modify Default Block Editor Settings

This code modifies the default block editor settings to update the image sizes.

function my_custom_block_editor_settings() {
  $default_settings = get_default_block_editor_settings();

  // Add custom image sizes to the default settings
  $default_settings['imageSizes'][] = array(
    'slug' => 'custom-image-size',
    'name' => __('Custom Image Size', 'textdomain'),
  );

  return $default_settings;
}

add_filter('block_editor_settings', 'my_custom_block_editor_settings');

Remove a Default Block Editor Setting

This code removes a default block editor setting, such as disabling the custom color palette.

function my_custom_block_editor_settings($settings) {
  $settings['disableCustomColors'] = true;
  return $settings;
}

add_filter('block_editor_settings', 'my_custom_block_editor_settings');

Change Default Block Editor Color Palette

This code changes the default color palette for the block editor.

function my_custom_block_editor_settings($settings) {
  $settings['colors'] = array(
    array(
      'name' => __('Primary Color', 'textdomain'),
      'slug' => 'primary',
      'color' => '#0073AA',
    ),
    array(
      'name' => __('Secondary Color', 'textdomain'),
      'slug' => 'secondary',
      'color' => '#E14D43',
    ),
  );

  return $settings;
}

add_filter('block_editor_settings', 'my_custom_block_editor_settings');

Add Custom Block Editor Font Sizes

This code adds custom font sizes to the block editor.

function my_custom_block_editor_settings($settings) {
  $settings['fontSizes'] = array(
    array(
      'name' => __('Small', 'textdomain'),
      'slug' => 'small',
      'size' => 12,
    ),
    array(
      'name' => __('Regular', 'textdomain'),
      'slug' => 'regular',
      'size' => 16,
    ),
  );

  return $settings;
}

add_filter('block_editor_settings', 'my_custom_block_editor_settings');