Skip to content

Disabling default presets (color, spacing, shadow, font size, aspect ratio, etc) still generates unused css variables on the frontend #75118

@EldarAgalarov

Description

@EldarAgalarov

These properties doesn't work as expected. After disabling them, Gutenberg continues generating bloated CSS with tons of unused CSS variables on the frontend:

{
	"$schema": "https://schemas.wp.org/wp/6.9/theme.json",
	"version": 3,
	"settings": {				
		"color": {
			"defaultDuotone": false,
			"defaultGradients": false,
			"defaultPalette": false			
		},
		"dimensions": {
			"defaultAspectRatios": false
		},		
		"shadow": {
			"defaultPresets": false
		},
		"spacing": {
			"defaultSpacingSizes": false
		},
		"typography": {
			"defaultFontSizes": false
		}
	}
}

Workaround:

add_filter( 'wp_theme_json_data_theme', function ( \WP_Theme_JSON_Data $theme_json ): \WP_Theme_JSON_Data {
	$data = $theme_json->get_data();

	$color = &$data['settings']['color'];
	if ( $color['defaultDuotone'] === false ) {
		$color['duotone']['default'] = array();
	}
	if ( $color['defaultGradients'] === false ) {
		$color['gradients']['default'] = array();
	}
	if ( $color['defaultPalette'] === false ) {
		$color['palette']['default'] = array();
	}

	$dimensions = &$data['settings']['dimensions'];
	if ( $dimensions['defaultAspectRatios'] === false ) {
		$dimensions['aspectRatios']['default'] = array();
	}

	$shadow = &$data['settings']['shadow'];
	if ( $shadow['defaultPresets'] === false ) {
		$shadow['presets']['default'] = array();
	}

	$spacing = &$data['settings']['spacing'];
	if ( $spacing['defaultSpacingSizes'] === false ) {
		$spacing['spacingSizes']['default'] = array();
	}

	$typography = &$data['settings']['typography'];
	if ( $typography['defaultFontSizes'] === false ) {
		$typography['fontSizes']['default'] = array();
	}

	$theme_json->update_with( $data );

	return $theme_json;
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions