From 9c4896cbcac35f9585040dd18de9a6161be29f06 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Thu, 7 Oct 2021 11:20:43 +0300 Subject: [PATCH] Opt-in to print styles for rendered blocks only and inlining them --- functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 79d2318d..b02039f8 100644 --- a/functions.php +++ b/functions.php @@ -21,6 +21,8 @@ function twentytwentytwo_support() { function twentytwentytwo_scripts() { // Enqueue theme stylesheet. wp_enqueue_style( 'twentytwentytwo-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) ); + // Add "path" data to the stylesheet to allow inlining it when possible in order to improve perfrormance. + wp_style_add_data( 'twentytwentytwo-style', 'path', get_template_directory() . '/style.css' ); } add_action( 'wp_enqueue_scripts', 'twentytwentytwo_scripts' ); @@ -35,4 +37,7 @@ function twentytwentytwo_editor_styles() { ) ); } -add_action( 'admin_init', 'twentytwentytwo_editor_styles' ); \ No newline at end of file +add_action( 'admin_init', 'twentytwentytwo_editor_styles' ); + +// Opt-in to only load styles for rendered blocks. +add_filter( 'should_load_separate_core_block_assets', '__return_true' );