Skip to content

CSS color variables are generated even if the defaults are disabled in theme.json #67268

@webexpr-dhenriet

Description

@webexpr-dhenriet

Description

Would it be possible to clarify the solution to use only what is needed and not load/write

  • color
  • gradients
  • duotone
  • CSS variables (:root)

This was mentioned here #43385, #40183, #56180

I think it's not very clear today, in the theme.json, for example, set settings.color.defaultPalette to false doesn't prevent the generation of css variables and CSS .has-** helpers, just like "settings.color.defaultGradients": false or "settings.color.defaultDuotone" : false.
Currently, the only solution I've found is this one

add_filter('wp_theme_json_data_default', function ($theme_json)
{
    $data = $theme_json->get_data();

    $data['settings']['color']['palette']['default'] = [];
    $data['settings']['color']['duotone']['default'] = [];
    $data['settings']['color']['gradients']['default'] = [];

    $theme_json->update_with($data);

    return $theme_json;
});

Step-by-step reproduction instructions

1 Add theme.jon
2 Add settings.color.defaultPalette, settings.color.defaultGradients, settings.color.defaultDuotone to false
3 Inspect DOM

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [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