PostCSS plugin to render WordPress global styles from a theme.json file and inline them.
As of now it only supports preset styles.
Add this keyword to one of the CSS files processed by PostCSS.
css/input.css
:
@wp-global-styles;
body {
background: black;
}
will give you
/* ... result of the rendered WordPress global styles inlined into the CSS file */
body {
background: black;
}
Type: String
Default: ./theme.json
The location where the theme.json will be loaded from.
Type: Function
Default: defaultMetadataGenerator
The function to generate the AST representation of the generated CSS classes for the color palette.
Type: Function
Default: defaultMetadataGenerator
The function to generate the AST representation of the generated CSS classes for color gradients.
Type: Function
Default: defaultMetadataGenerator
The function to generate the AST representation of the generated CSS classes for the font sizes.
Type: Function
Default: defaultMetadataGenerator
The function to generate the AST representation of the generated CSS classes for the font families.
Step 1: Install plugin:
npm install --save-dev postcss postcss-wp-global-styles
Step 2: Check you project for existed PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Step 3: Add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-wp-global-styles'),
require('autoprefixer')
]
}