I have enqueued google fonts in the usual way in functions.php:
function travellers_field_guide_scripts()
{
wp_enqueue_style('travellers-field-guide-style', get_stylesheet_uri(), array(), _S_VERSION);
wp_enqueue_style('googlefont_css', 'https://fonts.googleapis.com/css2?family=Alata&family=Lato:[email protected];400;700;900&display=swap', false);
}
add_action('wp_enqueue_scripts', 'travellers_field_guide_scripts');
However, upon checking the <head> all I see is this
<link rel="stylesheet" id="googlefont_css-css" href="https://fonts.googleapis.com/css2?family=Lato%3Awght%40300%3B400%3B700%3B900&display=swap&ver=5.4.2" media="all">
I’ve resorted to manually adding the link (exactly as I enqueued it) to the fonts in the header, and the fonts are downloaded as expected, but would be nice to know why WordPress mangles the googlefont when trying to enqueue it. I checked my theme, there is no other reference to googlefont except to enqueue so I’m not doing anything to mangle it.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
It looks like the URL is getting parsed somewhere and whatever does the parsing is probably internally only able to deal with one parameter for a particular name, so just keeps the second value for the family parameter.
As you have a valid usecase for having two parameters with the same name, you might want to file this as a bug.
If there are workarounds they could be hacky, so unfortunately adding to your header file might be the best solution for now, unless someone else can suggest another sensible way to add this to the header through hooks.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0