Archived topic
Function wp_dequeue_style was called incorrectly
3 replies · Started by Techibytes Media on July 21, 2022
So was trying to remove Google fonts with a generatePress child theme but encountered an error
Notice: Function wp_dequeue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the font-awesome handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/780543.cloudwaysapps.com/bxryqrrekh/public_html/wp-includes/functions.php on line 5831`
I had to uninstall it but if there is a way you could help me resolve this and possibly remove the Google fonts api from the function.php for me that would be appreciated too
Hi there,
I don't think you need to use any function to remove Google fonts, if you are not using Google fonts on your site, then it won't load.
Just make sure you are using the dynamic typography system:
https://docs.generatepress.com/article/dynamic-typography-overview/
If you are still using the old typography system, you can switch it to the dynamic system at customizer > general. https://docs.generatepress.com/article/switching-to-dynamic-typography/
I guess if i block the Google font from the typography section it will do the work? Because i just want to use Arial and not load anything that will bring up cases
using Google fonts API, this technology impacts LCP because it loads in lots of fonts in the form of CSS files that load in before the LCP element, these are render-blocking resources and will increase LCP loading times so we advise that you remove this technology
Hello there,
If you don’t choose any Google Font for any text in your site, through Typography or if you’re using GenerateBlocks, in the Block settings as well, Google fonts wont be loaded/enqueued. Basically, make sure that Google fonts is toggled off or not chosen anywhere.
If you want to try to dequeue it manually, here’s a code you may try:
add_action( 'wp_enqueue_scripts', function() {
wp_dequeue_style( 'generate-google-fonts' );
},99 );
Hope this clarifies!