Learn in this tutorial how to unregister Google fonts in the WordPress font library using code.
WordPress 6.5 introduces quite a few new features, one of the most prominent is the font library.
When you are using a block-based theme (for the time being), this feature allows you to edit, add and manage them fonts directly from the style editor.
This is a fantastic improvement that opens up a lot of customization options in a very easy way. In fact, by default it allows you to access Google fonts and download them directly from the web.
But if you are creating or managing websites for clients and all the necessary fonts are already configured, you may want to disable it, to prevent them from adding more.
Here’s how:
Snippet to unregister Google fonts from WordPress font library
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.
// Unregister Google Fonts
add_action( 'init', 'cg_remove_google_fonts' );
function cg_remove_google_fonts() {
wp_unregister_font_collection( 'google-fonts' );
}
{ /restrict}
It’s as simple as that.
Conclusions
The arrival of the font library makes it possible for any user to manage the fonts of a website. So, if you prefer that they use only the ones you have incorporated into the theme (or manually), now you know how to disable the option to install any Google font.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉