Find out in this tutorial how to stop WordPress block styles from loading when you don’t need them just using code.
With the arrival of WordPress 5.9 global styles were introduced, a fantastic feature but one that you’re only going to take advantage of if you’re using a block theme (or FSE).
The catch is that, regardless of the theme you’re using, all the CSS in the global styles is loaded in the header of all pages.
So, if you are not using a theme prepared to take advantage of global styles, you will probably want to avoid loading these styles.
Let’s see how you can achieve this.
Preventing inline global styles from loading in WordPress header
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this code you prevent wp_enqueue_global_styles
and wp_global_styles_render_svg_filters
functions, that are responsible for loading the global styles, from running.
Conclusions
Do you prefer to stop loading global styles that you are not going to use? Well, now you know how to prevent them from loading with a little bit of code.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂