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
Support "name" attribute in wp_register_webfonts
#46398
Comments
Not quite sure who could comment on this best and take a look at PR #46404 — @oandregal or @youknowriad you might know the best. :-) |
Maybe that's a good one for @hellofromtonya as it relates to the fonts API. |
This enhancement is now added to the Web Fonts API's Roadmap ✅ and the PR is blocked until the architectural work is merged ✅ . |
@hellofromtonya is it a good time to rebase this PR now that the API redesign is merged, or do you plan to continue refactoring the API? |
@simison There are 2 more blocking architectural PRs, one of which will rename the entire API and all of its code. A status update is here #41479 (comment). |
@simison This issue is now unblocked. Please note, the API has been completely redesigned including a brand new architecture and renamed to Fonts API (including all of the public function names). |
Some notes to help:
array(
array( /* font 1 */ ),
array( /* font 2 */ ),
) new array structure: array(
'Lato' => array(
array( /* variation 1 */ ),
array( /* variation 2 */ ),
),
) from an array of fonts to an array of font-families with each of the variations as an array to its keyed The font-family key can be its proper name. The API will automatically convert it into a handle. Thus, a |
Following up with @hellofromtonya's comment above, I've verified that using the updated fonts definition (keyed array) uses the provided key name in font pickers. These results support Tonya's assertion that a new Steps to Test
Expected Results
Supplemental ArtifactsFigure 1: Friendly font names displayed in global Styles picker. |
Update: This issue no longer applies to the Fonts API once the Font Library is merged. I believe this issue can be closed as the "name" attribute is supported in theme.json. Why? As shared in Ongoing Roadmap update #41479 (comment), the Fonts API will no longer provide the means to register or enqueue fonts. Instead, it will pull / get the fonts from Theme JSON and then process each to server-side generate and print the With the coming Font Library, theme.json schema / data is used for data workflow. The theme.json
Therefore, I think this issue can be closed. Thank you everyone for your contributions! |
What problem does this address?
When registering fonts from a plugin with
wp_register_webfonts
, we define afont-family
that then becomes the "name" of the font in Style picker.When registering fonts with themes with
theme.json
,fontFamilies
supports passing thename
attribute that then gets picked by the UI as font label in the dropdown.Using
fontFamily
as label works fine for most cases just fine. When a plugin provinding external font-provider (Google Fonts in our case), there isn't flexibility in pickign a nice font family name because the font family has to match the one passed to Google Fonts API.For example, language-specific fonts in Google fonts don't have pretty names:
Above list would be better served with human-readable labels. It would be great to be able to translate the parts inside brackets, too.
What is your proposed solution?
wp_register_webfonts
should supportname
attribute that then gets added to Theme JSON object.AlternativelyI looked altering theme json object with
wp_theme_json_data_theme
filter (as in example) but this felt rather messy for something as simple.The text was updated successfully, but these errors were encountered: