• Hey friends,

    is it possible to combine google font css files? I’m actually optimizing our SEO and i’ve a problem with the number of CSS files.

    Here you can take a look of it:
    https://i.ibb.co/f1479Kb/Is-it-possible-to-combine-that.jpg

    The point is, im using the brooklyn theme from unitedthemes adn im able (in other words i need to): change the font for each topic..
    https://i.ibb.co/g40qkgw/font-1.jpg
    https://i.ibb.co/yQGQSBz/font-2.jpg

    For example:
    Header1: Bold, font weight 500
    text: regular, font weight 200

    I need to find an easy way to get a less number of css files for making the website faster. In this topic the google fonts.. I actually cant find a way on google to combine them.. do you have any ideas?

    Best wishes
    izzed

    • This topic was modified 5 years, 6 months ago by izzed.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    The meta link tag to fonts.googleapis can have multiple fonts and weights listed, separated by pipes: family=Lato:400,700|Montserrat:400,700|Roboto:400,700. This loads all 3 fonts in 2 weights each for the page. But it’s not going to change what your theme does when you select various fonts. You could output such a combined link on your header template, but your theme will still try to load them again individually.

    The real issue lies with your theme’s method of loading fonts, so you should be asking your theme’s devs, not Google. Google will just tell you what I did in my first line.

    You should be enqueueing them in your functions.php

    function font_scripts() {
      
      wp_enqueue_style('montserrat',  'https://fonts.googleapis.com/css?family=Montserrat:400,700&display=swap');
    
    }
    add_action( 'wp_enqueue_scripts', 'font_scripts' );
    Thread Starter izzed

    (@izzed)

    Thank you guys for you response, i will try that asap and give you a response!:)

    Thread Starter izzed

    (@izzed)

    You should be enqueueing them in your functions.php

    function font_scripts() {
      
      wp_enqueue_style('montserrat',  'https://fonts.googleapis.com/css?family=Montserrat:400,700&display=swap');
    
    }
    add_action( 'wp_enqueue_scripts', 'font_scripts' );

    What does is change exactly?
    I actually wrote that code into my function.php but the number of css didnt change. do i need to change the font in my brooklyn theme to “theme font” instead of “google font”?

    Moderator bcworkz

    (@bcworkz)

    It adds a meta tag link with all fonts specified in one line. The theme is still doing its own thing with individual links. I’m not sure what a “theme font” is. If it’s still a Google font, it could be also loaded with the added enqueue style code. What you need is to have the theme not load any fonts at all. Does it have a generic choice like “serif” or “sans-serif”? That should cause it to not load any fonts.

    But then it will probably be setting the various styles for page elements to be that generic font and the Google fonts you are loading will not be used. Try overriding the theme’s style rules as needed with your own font-family rules in the Additional CSS panel of the customizer.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to combine google font css files?’ is closed to new replies.