• I’m building a block theme to work with Gutenberg full site editing and there are two fonts I want to load from my assets folder. The tutorials I found for accomplishing this in the theme.json file seemed simple enough. But I can’t get the bold or italicized font faces to work. they only display properly when I remove the “fontFace” setting from my theme.json. Which has me thinking that the font’s aren’t being loaded from the file at all and instead just display because I already have these fonts on my computer.

    The fonts do display as options in my site editor so they’re at least being registered for use on the site.

    I’ve tried using both woff2 & ttf fonts. And yes the path to my font files is correct. The theme.json is right inside my theme folder and the fonts are in /assets/fonts/[font name]/font-file.woff2

            "typography": {
                "fontFamilies": [
                    {
                        "fontFamily": "\"Raleway\", sans-serif",
                        "slug": "raleway",
                        "name": "Raleway",
                        "fontFace": [
    						{
    							"fontFamily": "Raleway",
    							"fontWeight": "400",
    							"fontStyle": "normal",
    							"fontStretch": "normal",
    							"src": [ "file:./assets/fonts/raleway/Raleway-Medium.ttf" ]
    						},
    						{
    							"fontFamily": "Raleway",
    							"fontWeight": "400",
    							"fontStyle": "italic",
    							"fontStretch": "normal",
    							"src": [ "file:./assets/fonts/raleway/Raleway-Italic.ttf" ]
    						}
    						,
    						{
    							"fontFamily": "Raleway",
    							"fontWeight": "700",
    							"fontStyle": "bold",
    							"fontStretch": "normal",
    							"src": [ "/assets/fonts/raleway/Raleway-Bold.ttf" ]
    						}
    					]
                    },
                    {
                        "fontFamily":  "\"Didot\", serif",
                        "slug": "didot",
                        "name": "Didot",
                        "fontFace": [
    						{
    							"fontFamily": "Didot",
    							"fontWeight": "400",
    							"fontStyle": "normal",
    							"fontStretch": "normal",
    							"src": [ "file:./assets/fonts/didot/Didot-Regular.woff2" ]
    						},
    						{
    							"fontFamily": "Didot",
    							"fontWeight": "500",
    							"fontStyle": "italic",
    							"fontStretch": "normal",
    							"src": [ "file:./assets/fonts/didot/Didot-Italic.woff2" ]
    						}
    						,
    						{
    							"fontFamily": "Didot",
    							"fontWeight": "700",
    							"fontStyle": "bold",
    							"fontStretch": "normal",
    							"src": [ "file:./assets/fonts/didot/Didot-Bold.woff2" ]
    						}
    					]
                    }
                ]
            },
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi there @shelaine, could you try removing all these lines:

    "fontStyle": "bold",

    I think the bold display comes from the numerical font weight itself (i.e. 700) and isn’t valid in FontStyle.

    Valid font-style values: https://developer.mozilla.org/en-US/docs/Web/CSS/font-style

    More about theme.json & typography: https://fullsiteediting.com/lessons/theme-json-typography-options/

    Thread Starter Shelaine Roustio

    (@shelaine)

    Hi @zoonini, thanks for your reply!

    That makes sense about "fontStyle": "bold", being invalid. I’ve tried removing that from my bold font face. I’ve also tried using "fontStyle": "normal", and playing with "fontWeight": "700", vs "fontWeight": "bold",. Nothing seems to be working.

    The theme.json typography link is exactly what I’ve been referencing to build mine.

    Any other suggestions?

    Moderator Kathryn Presner

    (@zoonini)

    @shelaine Thanks for trying that! Here are a few more things you could check:

    – To test your theory about whether the fonts are being loaded from your site or from your computer, temporarily deactivate Raleway on your computer and see if the font loads correctly or not.
    – Try loading the font with a full path starting with https:// and see if that makes a difference.
    – Double-check the spelling of the font file, including capitalization. For example, is it Raleway-Italic.ttf or raleway-italic.ttf?

    Let me know how it goes!

    Thread Starter Shelaine Roustio

    (@shelaine)

    Nvmd I think I solved it! The problem seemed to be a combination of corrupted woff2 files (I tried converting my ttf files because I read woff2 was the superior web font format) + I needed to flush my cache as a hard refresh wasn’t enough to show the changes. Removing "fontStyle": "bold" from my bold fonts was probably part of it too.

    Moderator Kathryn Presner

    (@zoonini)

    Awesome, glad you got it sorted! I’ll mark this as resolved but feel free to start a new thread if you have other questions. Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘fontFace in theme.json not working (can’t get bold or italic to work)’ is closed to new replies.