WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.34k stars 4.13k forks source link

How to remove "wp-block-navigation-link-inline-css" or "wp-block-site-logo-inline-css" #61237

Open tablufc88 opened 4 months ago

tablufc88 commented 4 months ago

Is it possible to remove inline styles with ids such as "wp-block-navigation-link-inline-css", "wp-block-site-logo-inline-css", "wp-block-list-inline-css" or "wp-block-image-inline-css"?

This doesn't do it - https://fullsiteediting.com/lessons/how-to-remove-default-block-styles/#h-how-to-remove-the-inline-styles-on-the-front

I'm not using an fse theme & have removed 'block-templates' support.

But I have added support for 'block-template-parts' so that I can create template parts for header and footer.

colorful-tones commented 4 months ago

@tablufc88, are you looking to remove the CSS altogether for each block, or do you just not want it inlined?

tablufc88 commented 4 months ago

@colorful-tones ideally I'd like to filter the styles to remove a couple of conflicts but it would be useful to know why they are showing on my page when they are not in the queue if you know? Possibly could be enqueued differently since I opted in for block-template-parts support?

Got rid of these inline styles with wp_deregister_style for now.

add_action('wp_enqueue_scripts', function () {
  wp_deregister_style('wp-block-navigation-link');
  wp_deregister_style('wp-block-navigation');
  wp_deregister_style('wp-block-image');
  wp_deregister_style('wp-block-list');
  wp_deregister_style('wp-block-site-logo');
});

When dumping the queue:

add_action('wp_enqueue_scripts', function () {
    global $wp_styles;
    dd($wp_styles->queue);
});

I get the following. I expected them to be in here:

[
  0 => "admin-bar"
  1 => "wp-block-heading"
  2 => "wp-block-paragraph"
  3 => "wp-block-button"
  4 => "wp-block-buttons"
  5 => "wp-block-block"
  6 => "wp-block-column"
  7 => "wp-block-columns"
  8 => "wp-block-library"
  9 => "classic-theme-styles"
  10 => "woocommerce-layout"
  11 => "woocommerce-smallscreen"
  12 => "woocommerce-general"
  13 => "woocommerce-inline"
  14 => "duplicate-post"
]

Thanks for your help

colorful-tones commented 4 months ago

Got rid of these inline styles with wp_deregister_style for now.

add_action('wp_enqueue_scripts', function () {
  wp_deregister_style('wp-block-navigation-link');
  wp_deregister_style('wp-block-navigation');
  wp_deregister_style('wp-block-image');
  wp_deregister_style('wp-block-list');
  wp_deregister_style('wp-block-site-logo');
});

Are you all set then? Are we good to close this out?

tablufc88 commented 4 months ago

Kind of but if they are not enqueued, why are the styled inlined in the first place?

t-hamano commented 4 months ago

why are the styled inlined in the first place?

I believe this is for performance improvement. You can check the post below for more details.

Block-styles loading enhancements in WordPress 5.8 – Make WordPress Core