0

so im making a custom theme for wordpress and im trying to enqueue the styling for the website, the css styling loaded successfully in the website but not the font styling it just wont work for some reason

here is the functions.php file :

<?php
   function wp_enqueue_styles(){
    wp_enqueue_style('font_style',"https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;700&family=Cormorant:wght@400;500;600;700&family=Outfit:wght@400;500;700&family=Pacifico&family=Roboto+Condensed:ital,wght@0,300;0,400;1,300&display=swap", array(),"1.0", "all");
    wp_enqueue_style('main_css',get_template_directory_uri() . "/style.css", array('font_style'),"1.0", "all");
}
add_action('wp_enqueue_scripts','wp_enqueue_styles');
?>

as i said style.css is working its just the fonts thats not

i tried making the font_style a dependency for it to load before main.css but it did not solve the problem

  • Does this answer your question? [Why can't I enqueue multiple Google Fonts in WordPress functions.php?](https://stackoverflow.com/questions/60953810/why-cant-i-enqueue-multiple-google-fonts-in-wordpress-functions-php) – Caleb Jun 20 '23 at 14:52

1 Answers1

0

This is because of how the Google Fonts URL is structured. There are multiple family query parameters, which means the last occurrence overrides the others. This is a known issue, and (last I knew) WordPress considers it an issue with Google Fonts, not its own URL processing.

The solution I've taken to is registering a separate stylesheet for each font needed, and then enqueueing each one as needed.

See answer here: https://stackoverflow.com/a/60954323/5490855

Caleb
  • 1,058
  • 1
  • 7
  • 18