-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webfonts API implementation in theme.json
#35591
Comments
Can we use I've also provided some thoughts on the use of I'll leave Jorge and others to provide any more details or thought, as they've looked into this in the past. |
+1 for using something under |
heavily related/previously: #34752 |
Hmmm using I'll use what we currently have in the TT2 theme as an example ( {
"fontFamily": "\"Source Serif Pro\", serif",
"name": "Source Serif Pro",
"slug": "source-serif-pro",
}
One option would be to nest the webfonts for each font-family in a {
"fontFamily": "\"Source Serif Pro\", serif",
"name": "Source Serif Pro",
"slug": "source-serif-pro",
"fontFace": [
{
"fontFamily": "Source Serif Pro",
"fontWeight": "200 900",
"fontStyle": "normal",
"fontStretch": "normal",
"src": "file:./assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2",
"provider": "local"
},
{
"fontFamily": "Source Serif Pro",
"fontWeight": "200 900",
"fontStyle": "italic",
"fontStretch": "normal",
"src": "file:./assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2",
"provider": "local"
}
]
} The other option would be to just add a new |
I like this simpler version but I would have used I would add also |
The code examples above are just examples and dont' include everything that's possible. When a webfont requires multiple font-files, you can use an array (that's already implemented in the API). In the case of TT2 we only have a |
It's not the same... |
As a proof of concept, I created a draft PR on #35625. The PR adds a simple function to register the webfonts if they are defined in |
@aristath I see this is currently not tracked on the Gutenberg 11.9 Project and therefore isn't targeted for 5.9. Is that correct? Is there any plan to have this feature in Core in 5.9 with the main Webfont API? |
Yes, we're planning to merge this in 5.9 in core. |
Ahh okay makes sense. Thanks for the clarification:) so it will actually ship in core before the plug-in 🤔 |
Well, it needs to... The plugin mods can't function unless the core code is there. So the order of committing needs to be core - Gutenberg - tt2 |
Of course we could merge this in Gutenberg, as it will only function when the core code gets merged... If we're pressed for time because of the feature-freeze deadline, we can merge the POC which is functional and safe, and then improve it. |
I opened the PR in #35625 and rebased it 👍 |
I like the option of using |
Since the API was not included in WP5.9, this is no longer relevant so I'll go ahead and close it. A draft PR is in the works to port the API to Gutenberg as per the comment on https://core.trac.wordpress.org/ticket/46370#comment:111. Draft PR: #36394 👍 |
This doesn't seem to work though. I had to download a variable font to get weights working |
Just to echo on what @poof86 was saying, I'm seeing that when defining fonts within
So in the above example only Roboto at |
I have the same problem loading multiple weights/styles of the same non-variable font. Only the first is getting loaded. Using the snippet below, merriweather-regular-webfont.woff2 and poppins-bold-webfont.woff2 is loaded.
|
Has a solution to the issue with multiple weight of the same font in the theme.json file been developed yet?? |
+1, same issue, but with different Related issue: #48813 |
In WP5.9 a new webfonts API will be included (see WordPress/wordpress-develop#1736).
The twentytwentytwo theme is a block-based theme, and it loads custom webfonts. There is a draft PR in the TT2 theme to implement the webfonts API (see WordPress/twentytwentytwo#95) but ideally webfonts would be defined in the theme.json file.
In the current form of the API, webfonts can be defined in PHP using code like this (example is from the TT2 theme PR):
That structure is easy to use in a
theme.json
file - which is why we went with this schema.So in
theme.json
we should be able to add a "webfonts" item and then parse the items and call the Webfonts-API functions to register the webfonts:The webfonts API takes care of generating the
@font-face
styles and adds them to the frontend as well as the editor (tested with the TT2 theme using the PR mentioned above).The only missing piece here is to decide ifwebfonts
intheme.json
should be a root-level item or maybe part ofsettings
? 🤷 . Then once we decide that, the JSON parser should be tweaked to allow registering the fonts.EDIT: It was decided to put these inside
settings.typography
. The code above was updated accordingly.As an additional benefit, maybe when parsing the webfonts in theme.json we could add then registered fonts in
typography.fontFamilies
automatically without requiring users to manually add them.cc @hellofromtonya @oandregal @youknowriad @jorgefilipecosta @scruffian @ntsekouras @mtias
Timeframe: Ideally this should be included in WP5.9 in order to be properly implemented & tested in the TT2 theme.
The text was updated successfully, but these errors were encountered: