Help with adding local fonts that are not Google

  • HI there,

    I read and watched the video for adding local fonts but it primarily focuses on Google fonts:

    https://docs.generatepress.com/article/adding-local-fonts/

    I have a custom font a client purchased on Creative Market and as I’ve never used @font-face, I would appreciate a little more guidance.

    I’m not sure how to generate the required CSS for example since I can’t use the tool mentioned in the document linked above.

    Can you perhaps provide some guidance in addition to that doc that deals with non Goggle fonts?

    For example, I’m not sure the specific name of the font that’s needed in the css and code snippet. I downloaded the files from Creative Market and uploaded to server — https://staging.energyembodiment.com/wp-content/uploads/2023/06/modernline-bold.woff2 — but what’s the name I use in CSS and code snippet?

    Thank you

  • Update: I’ve added this to my child theme’s style sheet as I uploaded the files via FTP in a fonts folder.

    @font-face {
        font-family: 'modernlinebold';
        src: url('https://staging.energyembodiment.com/fonts/modernlinebold.eot');
        src: url('https://staging.energyembodiment.com/fonts/modernlinebold.eot') format('embedded-opentype'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.woff2') format('woff2'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.woff') format('woff'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.ttf') format('truetype'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.svg#modernlinebold') format('svg');
    }
    

    And added the font — modernlinebold — in the customizer. But when I apply the new font in customizer, nothing happens. the font is not applied.

    What did I miss?

  • If you still need one, here is an article that may assist you: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face

    Also see: https://css-tricks.com/snippets/css/using-font-face-in-css/

    There are also several tools online that do the @font-face generation (and webfont conversion) for you – like this one: https://www.fontsquirrel.com/tools/webfont-generator

    Your code should work though. To test, can you try replacing it with this?:

    @font-face {
        font-family: 'modernlinebold';
        src: url('https://staging.energyembodiment.com/fonts/modernlinebold.eot') format('embedded-opentype'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.woff2') format('woff2'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.woff') format('woff'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.ttf') format('truetype'),
             url('https://staging.energyembodiment.com/fonts/modernlinebold.svg#modernlinebold') format('svg');
    }

    Is the SVG link correct as well?

    Lastly, if this doesn’t work, can you share the “password” to view your site through the Private Information field?

  • Thank you Fernando! Once I updated the CSS to what you shared, it “magically” works.

  • You’re welcome! Glad that worked!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.