• Resolved slobich

    (@slobich)


    After updating to WordPress 6.9 there are two inline styles on my page, global-styles-inline-css and wp-block-paragraph-inline-css. I can’t find any reference in the docs on how to remove them and none of the standard ways like using wp_dequeue_style() work. If I downgrade to 6.8.3 the styles are not added.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Those inline styles are intentionally injected by WordPress 6.9 for block themes (Global Styles and block-level CSS) and can’t be dequeued because they’re generated at runtime. To remove them, you must disable block styles (e.g., remove_theme_support(‘wp-block-styles’)) or filter wp_should_load_block_assets / Global Styles output—there’s no simple dequeue anymore.

    Moderator threadi

    (@threadi)

    You should be able to remove these outputs with

    wp_dequeue_style( 'global-styles' );
    wp_deregister_style( 'global-styles' );

    I just figured this out using the plugin https://wordpress.org/plugins/admin-site-enhancements/. It provides a function for exactly this purpose, and it’s in the source code, and it works for me with TwentyTwentyFive as the theme.

    If it still doesn’t work for you, take a look at how this plugin does it and adapt it for your own code.

    Thread Starter slobich

    (@slobich)

    @threadi thank you for your suggestion but as I said those standard functions like wp_dequeue_style() don’t have any effect also the handle of the script “global-styles” is not correct for the scripts in question since there are more of them. The scripts depend on the blocks used in the content so some sites I work on had different scripts since their content used different blocks, for example if you have a heading block you’ll get wp-block-quote-inline-css and so on. Eventually figured it out from this post on Stack overflow.

    For anyone else that has this issue you need to add add_filter( 'should_load_separate_core_block_assets', '__return_false' ); in your functions.

    It seems like with every new WordPress update I get CSS which I don’t need and then have to figure out a new way to remove it.

    wouter85

    (@wouter85)

    For me this was working the correct way in my theme to completely disable anything from the global-styles-inline-css. This workaround works for WP 6.9

    /**
    * Remove WordPress block styles completely.
    */
    add_action('wp_enqueue_scripts', function() {
    // Remove all WordPress block styles
    wp_dequeue_style('wp-block-library');
    wp_dequeue_style('wp-block-library-theme');
    wp_dequeue_style('wc-blocks-style'); // WooCommerce blocks
    wp_dequeue_style('classic-theme-styles');
    wp_dequeue_style('global-styles');
    }, 100);

    /**
    * Remove block styles from admin/editor as well.
    */
    add_action('admin_enqueue_scripts', function() {
    wp_dequeue_style('wp-block-library');
    wp_dequeue_style('wp-block-library-theme');
    });

    /**
    * Disable WordPress global styles (theme.json output).
    */
    add_filter('wp_theme_json_get_style_nodes', '__return_empty_array');

    /**
    * Remove global styles inline CSS completely.
    */
    remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
    remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘WordPress 6.9 adds global-styles-inline-css and wp-block-paragraph-inline-css’ is closed to new replies.