This uses PostCSS and postcss-palettize-colors to automatically convert any colors in your CSS to the new color palette in WordPress admin. It uses a basic color difference algorithm to convert any color to the closest color in the palette.
To use it, follow the usage guide from PostCSS for your setup. Follow the postcss.config.js
in this gist to add the postcss-palettize-colors
to your process. Make sure to define the palette colors using the paletteOptions
.
-
Install the dependencies
npm i postcss postcss-cli https://github.com/ryelle/postcss-palettize-colors.git
-
Configure PostCSS - download the
postcss.config.js
in this gist. This includes the full color palette for wp-admin. -
Run PostCSS via command line.
npx postcss style.css --replace
Swap out
style.css
for the path to your CSS file. Note, this will overwrite your CSS file with the new color values.Alternately, if you need to match colors in both 5.7 and older WordPress: you could use this command to create a separate 5.7-specific stylesheet, and check the version of WordPress to enqueue the correct CSS for each version.
npx postcss style.css -o style-57.css
See postcss-cli for more configuration options.
Does this config work correctly with the spaces inside the quotes?