How to enqueue Google Fonts v2 (CSS2) the correct Envato way?

Hello there,
I’m here to know how to enqueue Google Fonts CSS2 the correct Envato way? As we know Envato recommends this with Pipe sign ( | ) (if multiple fonts) [Enqueue Google fonts in WordPress theme · GitHub] to enqueue Google fonts on WordPress. But as CSS API version has been updated on Google Fonts, if we change css to css2, it does not load the fonts.

Will someone suggest how to properly enqueue Google Fonts with the latest CSS2 version?

Thanks & Regards

This is not the good way and you will be requested to update/fix the coding. This is a common issue and there’re too many similar threads on the forum.

I’ve searched before posting here. The fix you’re referring is Google Font v1. Google fonts has now updated to the latest version css2. I had followed this enqueue style and changed the google link to this…
[//fonts.googleapis.com/css2]

But it does not load the fonts when I add [css2] at the end of the link. Now Envato Reviewers giving a Soft Rejection for enqueue the Google fonts v1 they’re suggesting to use v2. Can you please tell how to load the fonts with Google Fonts new version2 [css2]?

Thanks

Try this:

add_action( 'wp_enqueue_scripts', 'ki__themes_googlefonts' );
function ki__themes_googlefonts() {
wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&family=PT+Serif:wght@400;700&display=swap', array(), '1.0.0');
}

I have tried this before. But it shows an error for WordPress Coding Standards like this…

Resource version not set in call to wp_enqueue_style(). This means new versions of the style will not always be loaded due to browser caching.

How to solve this error and give a version on the null value?

Just updated the code

If you define any version (ex: 1.0.0), it doesn’t load multiple fonts. It’s only loading one font.