Skip to content

Commit 136b585

Browse files
committed
Bundled Themes: Add CSS minification support to Twenty Twenty-One
1 parent 2389646 commit 136b585

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎src/wp-content/themes/twentytwentyone/functions.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,15 @@ function twenty_twenty_one_scripts() {
400400
// Note, the is_IE global variable is defined by WordPress and is used
401401
// to detect if the current browser is internet explorer.
402402
global $is_IE, $wp_scripts;
403+
$theme_version = wp_get_theme()->get( 'Version' );
404+
$suffix = SCRIPT_DEBUG ? '' : '.min';
405+
403406
if ( $is_IE ) {
404407
// If IE 11 or below, use a flattened stylesheet with static values replacing CSS Variables.
405-
wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/assets/css/ie.css', array(), wp_get_theme()->get( 'Version' ) );
408+
wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/assets/css/ie.css', array(), $theme_version );
406409
} else {
407410
// If not IE, use the standard stylesheet.
408-
wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
411+
wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/style' . $suffix . '.css', array(), $theme_version );
409412
}
410413

411414
// RTL styles.

‎src/wp-content/themes/twentytwentyone/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/wp-content/themes/twentytwentyone/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twentytwentyone",
3-
"version": "2.7.0",
3+
"version": "2.7",
44
"description": "Default WP Theme",
55
"author": "The WordPress Contributors",
66
"license": "GPL-2.0-or-later",
@@ -22,6 +22,7 @@
2222
"@wordpress/stylelint-config": "^21.30.0",
2323
"autoprefixer": "^10.4.22",
2424
"chokidar-cli": "^3.0.0",
25+
"cssnano": "^7.1.2",
2526
"eslint": "^8.57.1",
2627
"minimist": "^1.2.8",
2728
"npm-run-all": "^4.1.5",
@@ -67,6 +68,7 @@
6768
"build:ie": "postcss style.css -o assets/css/ie.css",
6869
"build:ie-editor": "postcss assets/css/style-editor.css -o assets/css/ie-editor.css",
6970
"build:stylelint": "stylelint **/*.css --fix --config .stylelintrc-css.json",
71+
"build:minify": "postcss style.css --use cssnano -o style.min.css --no-map",
7072
"build": "run-s \"build:*\"",
7173
"watch": "chokidar \"**/*.scss\" -c \"npm run build\" --initial",
7274
"lint:scss": "stylelint **/*.scss",

‎src/wp-content/themes/twentytwentyone/style.css‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Twenty Twenty-One WordPress Theme, (C) 2020 WordPress.org
1919
Twenty Twenty-One is distributed under the terms of the GNU GPL.
2020
*/
2121

22+
/*
23+
* IMPORTANT: This file is only served on the frontend when `SCRIPT_DEBUG` is enabled;
24+
* in most instances, the `style.min.css` file will be served. This theme uses SCSS for styles.
25+
* After making changes to SCSS files, run `npm run build` in the theme directory to compile
26+
* SCSS to CSS and regenerate the minified version.
27+
*/
28+
2229
/**
2330
* SETTINGS
2431
* File-header..........The file header for the themes style.css file.

0 commit comments

Comments
 (0)