Google Fonts not connecting

Started by Term, Aug 06, 2022, 10:48 AM

Previous topic - Next topic

TermTopic starter

Friends, hello everyone.

Below is an excerpt from functions php. I do not understand why the fonts are not connected? What's my mistake?
1 <?php
2     add_filter
('show_admin_bar''__return_false');
3  
4     add_action
('wp_enqueue_scripts''site_scripts');
5     function site_scripts() {
6         wp_enqueue_style('googleapsis''https://fonts.googleapis.com');
7         wp_enqueue_style('gstatic''https://fonts.gstatic.com');
8         wp_enqueue_style('google-fonts''https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&family=Montserrat:wght@400;600;700&family=Mulish:wght@400;700&display=swap');
9         wp_enqueue_style('main-style'get_stylesheet_uri(), array(), '0.0.0.0');
10     }
11 
12 ?>
When connecting via header php via link everything works...
Maybe the fonts are not all right?
  •  

Newport

News this summer.
WordPress.org recommends that theme authors work exclusively with local web fonts.
In light of a recent lawsuit in Germany where a website owner was fined for violating the GDPR by implementing Google fonts, the WordPress team has begun recommending the correct placement of web fonts. Most theme developers include Google fonts via a CDN to improve performance, but it turned out that this method exposes the IP addresses of visitors.

"The WP team strongly encourages developers to update all of their projects," said a Themes Team representative in a recent announcement. "We recommend switching to local fonts. Fonts from Google can be easily downloaded and shipped with the theme. As a result, users will be able to work with such web fonts locally, which does not violate GDPR rules."

The main team members are now working on changing all default themes, from Twenty Twelve to Twenty Seventeen - they are being transferred to local web fonts. The issue had been discussed before, but was put on hold until a recent court case when it was brought up again. One user complained on the German support forums that he created a small site based on the Twenty Seventeen theme, after which he was threatened by site visitors, citing a court decision. Ignoring the rules is punishable by a fine of €250,000 per incident, or, alternatively, a six-month prison sentence if the site owner does not stop working through the Google CDN, thereby inadvertently publishing users' IP addresses.

I recommend looking at Twenty Twenty-Two to understand how to properly ship local web fonts via theme.json. I think you should follow the guide:
https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/
  •  

_AnnA_

#2
Newport, they caught up with so much fear ...
You could just write: "It is impossible - they will fine you." This is probably why the Term construct does not run. Google doesn't sleep. :)
Well, the developers will not immediately rush to change their themes until they are asked for money.
What should ordinary users do, do they finish everything with pens?

No. A good person made a little plugin called Local Google Fonts that detects the source of Google fonts and allows them to be downloaded for local use. Simple and easy.
"Install and forget" is the plugin category.
Enjoy. :)
  •  

Newport

Another useful plugin: OMGF | Host Google Fonts Locally. The description says it all, but briefly:
  • Makes fonts preload, this helps improve "Cumulative LayoutShift" in Page Speed.
  • Removes unused fonts in themes and plugins.
  • Specifies the fallback font stack.
  • If necessary, to speed up page loading, changes font families to system fonts.
  •  

TermTopic starter

Thank you all very much. Now everything works.
Fonts are loaded and served from a local directory via https.

By the way, I found a good plugin for VP with a huge number of Google fonts.
Easy Google Fonts
You can easily pick up an interesting one in the visual editor. Without dancing with a tambourine and writing scripts.
Of course, fonts should not be connected through it, due to the GDPR problem discussed above, but you can use it to check how a particular font will look on the site.
  •