Skip to content

Conversation

@youknowriad
Copy link
Contributor

What?

Closes #64409

This PR enables the Fonts page for classic themes. That said, the fonts page relies on Global styles working to be able to work properly:

  • We need to be able to save global styles
  • We need global styles to generate CSS properly to be able to use the fonts in posts, pages...

This basically means that by enabling fonts, we're literally enabling all of global styles for classic themes (the UI for global styles remain hidden for the context of this PR).

I tested this briefly using 2019 theme, I installed some fonts, used them in some posts... Things are working decently to be honest. Now, I'm well aware that enabling global styles CSS generation can potentially have some side effects on these themes.

So I'd like some help from folks to test different kind of classic themes to see if this PR impacts frontend rendering in any way. Also check that you can install fonts and use them.

@youknowriad youknowriad self-assigned this Dec 12, 2025
@youknowriad youknowriad added [Type] Enhancement A suggestion for improvement. Needs Testing Needs further testing to be confirmed. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Feature] Font Library labels Dec 12, 2025
@github-actions
Copy link

github-actions bot commented Dec 12, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: SirLouen <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: matiasbenedetto <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mrleemon <[email protected]>
Co-authored-by: Drivingralle <[email protected]>
Co-authored-by: annezazu <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@SirLouen SirLouen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Report

Description

✅ This report validates that the indicated patch works as expected.

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.3
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 142.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Seventeen 4.0
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 22.3.0-rc.1
    • Test Reports 1.2.1

Testing Instructions

  1. Go to Appearance > Fonts
  2. Upload a new font
  3. Create a new post
  4. Add a paragraph, and in Block > Typography select Font
  5. Select the uploaded font

Actual Results

  1. ✅ Issue resolved with patch.

Additional Notes

  • @youknowriad can you do a little overview of what is being introduced apart from adding fonts for classic themes? Like a more comprehensive list of items to be tested. Judging by the code, I feel that more things can be achieved apart from just what I tested.

Supplemental Artifacts

image image

@SirLouen
Copy link
Member

SirLouen commented Dec 12, 2025

More Testing

Fonts not selectable in

2010 theme

image

2011 theme

image

And 2020 also tested.

@youknowriad
Copy link
Contributor Author

can you do a little overview of what is being introduced apart from adding fonts for classic themes? Like a more comprehensive list of items to be tested. Judging by the code, I feel that more things can be achieved apart from just what I tested.

It's explained in the description. The only visible addition here is "fonts for classic themes" but to be able to do that, we had to lift some conditions to generate CSS out of global styles for classic themes. And my fear is whether the removal of these conditions has any unwanted effect on the frontend of sites using classic themes (with or without custom fonts). I have no way to know 100% outside testing classic themes and ensure the changes don't impact them.

@youknowriad
Copy link
Contributor Author

Are they binded to the theme when you upload them?

Yes, like all global styles changes, you have to go to the "fonts" page and "activate them" again. Making them persist with theme switches is out of scope.

@SirLouen
Copy link
Member

Are they binded to the theme when you upload them?

Yes, like all global styles changes, you have to go to the "fonts" page and "activate them" again. Making them persist with theme switches is out of scope.

Ok, all good then 👍

@SirLouen
Copy link
Member

Tested now in

  • 2010✅
  • 2011✅
  • 2012✅
  • 2013✅
  • 2015✅
  • 2016✅
  • 2017✅
  • 2019✅
  • 2020✅
  • 2021✅
    Looking good in the front end for all variants.

@@ -0,0 +1,144 @@
<?php
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file is only here to override the Core behavior, but in reality there's no really change here from core behavior outside calling the overridden Gutenberg theme.json functions...

* @param WP_Theme $theme Theme object used to create response.
* @return WP_REST_Response Modified response object.
*/
function gutenberg_rest_theme_global_styles_link_rel_7_0( $response, $theme ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just makes the global style id available in theme endpoint. I believe @t-hamano opened a trac ticket about this a few days ago as well.

@jasmussen
Copy link
Contributor

Nice win!

@SirLouen
Copy link
Member

SirLouen commented Dec 12, 2025

@youknowriad after experimenting a bit with lib/compat/wordpress-7.0/global-styles.php I've created a test in #73974 that could be worth checking. I've added this as a PR to this branch.

Apart from this, for the rest all looking good to me. Maybe some collisions could appear with blocks or custom themes, but I could not find anything else.

@youknowriad
Copy link
Contributor Author

To be honest, I don't believe the tests add much value, especially since the main reason for the existing of the code is to override what code does by just calling the gutenberg functions. It's a code that is meant to be removed from Gutenberg (and core) and won't persist in any repo.

@github-actions
Copy link

Flaky tests detected in 6d5be3a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20171563157
📝 Reported issues:

@SirLouen
Copy link
Member

To be honest, I don't believe the tests add much value, especially since the main reason for the existing of the code is to override what code does by just calling the gutenberg functions. It's a code that is meant to be removed from Gutenberg (and core) and won't persist in any repo.

Ok, I don't have all the context for the intention of these introdutions
So apart from this, I could not find anything else. Feel free to close the corresponding PR.

@youknowriad
Copy link
Contributor Author

I really appreciate the help with both the automated tests and the testing. Thanks a lot :). I'm going to leave this PR open for a bit more feedback and testing and maybe we can move forward early next week.

foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
foreach ( $font_families as $definition ) {
// Skip if "fontFace" is not defined, meaning there are no variations.
if ( empty( $definition['fontFace'] ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( empty( $definition['fontFace'] ) ) {
$font_faces = $definition['fontFace'];
if ( empty( $font_faces ) ) {

Comment on lines +43 to +47
if ( empty( $definition['fontFamily'] ) ) {
continue;
}

$font_family_name = $definition['fontFamily'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( empty( $definition['fontFamily'] ) ) {
continue;
}
$font_family_name = $definition['fontFamily'];
$font_family_name = $definition['fontFamily'];
if ( empty( $font_family_name ) ) {
continue;
}


// Convert font face properties.
$converted_font_faces = array();
foreach ( $definition['fontFace'] as $font_face ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foreach ( $definition['fontFace'] as $font_face ) {
foreach ( $font_faces as $font_face ) {

Comment on lines +49 to +57
if ( str_contains( $font_family_name, ',' ) ) {
$font_family_name = explode( ',', $font_family_name )[0];
}
$font_family_name = trim( $font_family_name, "\"'" );

// Skip if no font family is defined.
if ( empty( $font_family_name ) ) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this section.
If the $font_family_name happens to be a string with comma separated font names, it will convert it into an array

But after conversion to array, it executes a trim? Maybe you were looking for an array_map('trim', ...)? I'm have not dug too much into the format of the fontFamily, but finally it checks again if it's empty. Is there any chance of having a fontFamily like this , ?

@SirLouen
Copy link
Member

SirLouen commented Dec 13, 2025

Additional Testing

I've been playing around with a custom classic theme with a default global font:

Here the playground testing environment:
https://playground.wordpress.net/?blueprint-url=https%3A%2F%2Fgist.githubusercontent.com%2FSirLouen%2F07cd5efa2e9ae0df553c933593f6feff%2Fraw%2F8e184826660caeca70e72b9f3f4973d9b6b310a9%2Fblueprint.json&gutenberg-branch=add%2Fenable-fonts-classic-themes

This is the raw blueprint: https://gist.githubusercontent.com/SirLouen/07cd5efa2e9ae0df553c933593f6feff/raw/8e184826660caeca70e72b9f3f4973d9b6b310a9/blueprint.json

I've added a font to the custom theme.

And then added a custom font to a paragraph of text

But the font is not applying in the_excerpt which is probably expected as it's being removed from all block styles and full fallback to default styles.

✅ But in the the_content its working fine and taking precedence.

Template Code

<!-- wp:paragraph -->
<p>Experimenting without font</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"fontFamily":"limelight"} -->
<p class="has-limelight-font-family">Experimenting with font</p>
<!-- /wp:paragraph -->

Backend:

image

Frontend with the_excerpt

image

Frontend with the_content

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Font Library [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Testing Needs further testing to be confirmed. [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider exposing the Font Library for classic themes

4 participants