I am trying to import three google fonts by adding the following to my functions.php
file:
function get_google_fonts() {
wp_enqueue_style( 'get-google-fonts', 'https://fonts.googleapis.com/css2?family=Alata&family=Baloo+Tamma+2&family=Roboto:wght@100&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'get_google_fonts' );
However, WordPress seems to be enqueueing only the last font (here, Roboto
) when I view my site.
<link rel="stylesheet" id="get-google-fonts-css" href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap&ver=5.5" type="text/css" media="all">
The site is new and WordPress is just installed. There are no plugins installed yet. What is the reason for this?
EDIT:
I tried splitting up the fonts into separate enqueues as follows and the fonts are all working now:
function get_google_fonts() {
wp_enqueue_style( 'get-font-1', 'https://fonts.googleapis.com/css2?family=Alata&display=swap', false );
wp_enqueue_style( 'get-font-2', 'https://fonts.googleapis.com/css2?family=Baloo+Tamma+2&display=swap', false );
wp_enqueue_style( 'get-font-3', 'https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'get_google_fonts' );
But I don't understand why the single request approach didn't work.