-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Document how to include to a 3rd party typeface in global styles #34752
Comments
I wonder if this could be useful as a core function. I suspect every theme using a Google font will copy/paste this. |
I think it would make a great core function so +1 to having it rolled in or a least documented. |
Note there's some ongoing work to make font assets more recognizable across WordPress: WordPress/wordpress-develop#1573 |
The patch on WordPress/wordpress-develop#1573 adds some generic functions like |
Is this issue still relevant? |
I think so. Coming from someone who wants to change the font (which I'd distribute with the theme) to a block theme that I found: I first checked: https://wordpress.org/search/font/
Then, I decided to try what I did in first comment (I updated it to add instructions for a 3rd party font) and that successfully load a couple 3rd-party fonts into the site editor. (again, I didn't test this very much but the fonts are available at wp-admin/site-editor.php?canvas=edit and if I select them in the typography sidebar panel at that page, they immediately load in the site editor. However, I'd defer to you whether you want to wait until that's including Gutenberg to close this; or to just document what I did above as a stop-gap. |
The docs in the Theme Handbook should cover this: https://developer.wordpress.org/themes/global-settings-and-styles/settings/typography/#registering-web-fonts-font-faces Does this cover everything you're asking for @skorasaurus? If not, I'd recommend opening a ticket in the Documentation repository (with the |
Thanks @justintadlock ; thanks for the heads up: I was able to get a custom font up and running in less than 10 minutes with the docs. |
Description
Not sure where in the documentation it would go; but fellow users would benefit to have documentation how to include a 3rd party typeface (one that is not local to a user's device) into Global Styles/theme.json
I figured how to load a font that is locally hosted and included in my theme:
Global Styles reads the value from a
@font-face
selector in the theme's CSS.(Example scenario, the font is in the theme's folder fonts)
Then in the theme.json file,
fontFamily
property needs to match the value of font-family's property in the CSS declaration.the slug value is a custom string - that you can choose the name of (I choose 'custom-slug' in the example below) and it'll available will be a CSS variable and its name will follow the structure specified in https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/#presets
--wp--preset--font-family--custom-slug
For example, with the declaration above in css;
For a remote font, something like following in a css file
Semi-related:
I don't know what best practices have been documented anywhere for loading 3rdparty fonts into WordPress
For Google, I found https://github.com/Automattic/themes/blob/1aa5058bcff44951877c2db4f461fd4a46433613/blockbase/functions.php#L75
That is then read in a blockbase child theme https://github.com/Automattic/themes/blob/1aa5058bcff44951877c2db4f461fd4a46433613/quadrat/theme.json#L390
The text was updated successfully, but these errors were encountered: