New Google Fonts URL incompatible with wp_enqueue_style()
-
The new Google Fonts changed how the generated URL to import the CSS font file on a site.
Old Google font format
https://fonts.googleapis.com/css?family=Open+Sans:400,700|PT+Serif:400,700&display=swap
New Google font format
https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=PT+Serif:wght@400;700&display=swap
The new format uses the ‘family’ parameter name twice in the query string and wp_enqueue_style() will only recognize the last one.
So running the following code will only actually add the PT Serif font and weights:
wp_enqueue_style( 'twd-googlefonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=PT+Serif:wght@400;700&display=swap' );
I’m mainly curious why WordPress is ignoring or stripping the previous parameter if the names are the same and if there is any way to prevent WordPress from doing that so it is compatible with adding Google fonts via the URL.
- The topic ‘New Google Fonts URL incompatible with wp_enqueue_style()’ is closed to new replies.