Add a custom font to my theme via the assets repository

Hello,
I am trying to add a custom font to my theme but it doesn’t work… I certainly did something wrong but I can’t find where.

  • I am developing my own theme that I installed via github.
  • In the assets repository, I uploaded my fonts that are not Google fonts :

  • In the about.json, I imported the files :

Capture d’écran 2023-04-06 à 11.09.51

  • In my scss repository, I created my font families :

Capture d’écran 2023-04-06 à 10.58.07

I tried to add : format(‘woff2’) but it doesn’t work neither.

  • And then :

Capture d’écran 2023-04-06 à 11.07.22

Well, it does not work… Any idea ?

2 Likes

I am not sure what the issue night be. I’d look at Include assets (e.g. images, fonts) in themes and components. Sorry if that’s not helpful.

2 Likes

Hi @Joart,

I’m sure I’m oversimplifying, but I notice in your about.json snippet, the path to the fonts points to an assets folder, but in your css, the path points to a fonts folder. Are you sure the css source path is correct?

5 Likes

This is a good catch, but you don’t want to use the path in your CSS like this, you should reference the files using the asset name as a variable:

@font-face {
   font-family: supply-light;
   src: url($supply-light);
}

This is covered in Include assets (e.g. images, fonts) in themes and components

8 Likes

Well I tried but it doesn’t work :frowning:

It’s hard to guess why. You might put your theme on github and link to it or post your code here.

Did you follow the example provided by @awesomerobot?

1 Like

Hi @Joart,

I played with this a bit on a fairly new Discourse instance, and had some trouble with the first few fonts I tried. I had converted them to .woff2 using a free, online converter, and I think maybe it didn’t do a good job.

When I tried with an .otf font and again with another .woff2 font converted by a more reputable converter, I was able to add the custom font using the steps in guide @pfaffman and @awesomerobot linked.

It really only took two steps - uploading the file using the Add Upload modal, and adding just the @font-face and body lines of the example SCSS to the theme or component.

I’m sure if you can tell give us more detail and share your code and the fonts, we can help you get this figured out.

3 Likes

Oh Yes, thank you! I tried with the ttf format and it works!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.