WordPress 6.5 The release adds a Font Library feature that allows users to manage fonts directly in the editor. This feature also provides a set of APIs that allow developers to control, tweak, and disable the behavior of the font library.
collection of fonts
A font set is a list of fonts that a user can install through the editor. In WordPress 6.5, these font families are defined through a fontFamily entry in the theme.json format. By default, WordPress 6.5 allows users to choose from a list of Google font collections. Note, however, that installing Google fonts will download the files to the WordPress server in order to ensure that the site is GDPR compliant.
Once a font collection is registered, it will be displayed in the editor's Font Library UI. From here the user can easily install and activate the desired fonts.
![Image[1]-WordPress 6.5 new features: font library comprehensive analysis - Photon Flux | Professional WordPress repair service, worldwide, rapid response](https://www.361sale.com/wp-content/uploads/2024/03/image-87-1024x605.png)
Add font set
You can use thewp_register_font_collection()function to add a new font collection. This can be done by providing the font family and its font list in PHP or JSON format in the font collection array.
The following is an example of adding a collection of fonts to PHP:
Please note.Font Collectionarraynamerespond in singingdescriptionfields need to support translation, which can be done by wrapping the string in the_x()function to do so. Typically, font family names do not need to be translated. For more information and background discussion on this topic, see the#60509The
In JSON format, the fieldsfont_familiesThis can be a local path or a JSON file pointing to a remote URL.
Delete font set
You can disable the font collection by using the wp_unregister_font_collection() function. The following is an example of disabling the default font collection:
![Image[2]-WordPress 6.5 new features: font library comprehensive analysis - Photon Flux | Professional WordPress repair service, global scope, fast response](https://www.361sale.com/wp-content/uploads/2024/03/image-91.png)
For more information, see#57980The
Installation and activation of fonts
The font settings are based on theFont definition in theme.json formatWhen you "install" fonts on your site, it saves those settings to a database so any theme can use them. When you "install" fonts on your site, it saves those settings to a database so that any theme can use those fonts.
Once the fonts are "activated", the theme's overall styling will be updated to include these fonts. You can use these fonts in global styles and individual block layout settings.
When you switch to a new theme, the installed fonts need to be reactivated so that the new theme can use the styles of those fonts. If you reset the theme's global styles, all installed fonts will be deactivated, but they remain on the site and can be reactivated as needed.
In addition, you can also utilize font libraries to deactivate fonts included in the theme, which will improve the loading speed of your website.
$font_families = [
array(
'font_family_settings' => (
array (
'fontFamily' => 'Open Sans, sans-serif',
'slug' => 'open-sans',
'fontFace' => (
array (
'fontFamily' => 'Open Sans',
'fontStyle' => 'normal',
'src' => 'https://fonts.gstatic.com/s/opensans/v40/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0C4iY1M2xLER.woff2'
),
array (
'fontFamily' => 'Open Sans',
'fontStyle' => 'italic',
'src' => 'https://fonts.gstatic.com/s/opensans/v40/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkaVIUwaERZjA.woff2'
),
),
), ), ), ), ), ), ), ), )
), ), ), ), ), ), ), ), )
'categories' => [ 'sans-serif' ],
),
array(
'font_family_settings' => (
array (
'fontFamily' => 'Monoton, system-ui',
'slug' => 'monoton',
'fontFace' => (
array (
'fontFamily' => 'Monoton',
'fontStyle' => 'normal',
'fontWeight' => '400',
'src' => 'https://fonts.gstatic.com/s/monoton/v19/5h1aiZUrOngCibe4fkPBQ2S7FU8.woff2',
'preview' => 'https://s.w.org/images/fonts/17.7/previews/monoton/monoton-400-normal.svg'
),
),
)
),
'categories' => [ 'display' ],
),
array(
'font_family_settings' => (
array (
'fontFamily' => 'Arial, Helvetica, Tahoma, Geneva, sans-serif',
'slug' => 'arial',
)
),
'categories' => [ 'sans-serif' ],
),
];
$categories = [
array(
'name' => _x( 'Display', 'Font category name' ),
'slug' => 'display',
),
array(
'name' => _x( 'Sans Serif', 'Font category name' ),
'slug' => 'sans-serif',
),
].
$config = array (
'name' => _x( 'My font collection', 'Font collection name' ),
'description' => _x( 'A collection of my favorite fonts.', 'Font collection description' ),
'font_families' => $font_families, 'font_families' => _x( 'A collection of my favorite fonts.
).
wp_register_font_collection ( 'my-font-collection', $config );
Customize the font upload directory
Note that some details (e.g. function names) may have changed prior to version 6.5. You can check the#60751and the question of Gutenberg#59699. for more information.
By default, uploaded fonts will be stored in thewp-content/fontscatalog. However, you can use thefont_dirFilters customize this location as needed. For those who do not support modifying thewp-contentdirectory will be installed using thewp-content/uploads/fontsas an alternate catalog.
You can use thewp_get_font_dir()function to get the location of the font upload directory.
The following example changes the fonts directory to the WordPress "Uploads" directory (default iswp-content/uploads):
![Image[3]-WordPress 6.5 new features: font library comprehensive analysis - Photon Flux | Professional WordPress repair service, worldwide, rapid response](https://www.361sale.com/wp-content/uploads/2024/03/image-94.png)
When modifying the upload location, it is important to ensure that the selected location exists and that the appropriate read/write permissions are set.
Like the wp-content/uploads directory, the font uploads directory is not subject to thewp_is_file_mod_allowed/DISALLOW_FILE_MODSrestrictions that allow font uploads.
If you need more information, see#59417respond in singingthis articleThe
How to disable font library
By default, you can easily access the font library through the editor.
Disable User Interface
You can turn off the customization interface for editor settings by using filters.
![Image[4]-WordPress 6.5 new features: font library comprehensive analysis - Photon Flux | Professional WordPress repair service, global scope, fast response](https://www.361sale.com/wp-content/uploads/2024/03/image-95.png)
Disabling the REST API
utilizationunregister_post_type()function removes the article type associated with a font library and can be implemented by extending the REST API.
![Image[5]-WordPress 6.5 new features: font library comprehensive analysis - Photon Flux | Professional WordPress repair service, global scope, fast response](https://www.361sale.com/wp-content/uploads/2024/03/image-96.png)
Doing so allows the extension to disable the font library functionality while retaining the user interface used to manage fonts for the current theme.
If you need more information, please see#55275respond in singing#57818The
New REST API
The Font Library feature introduces three new REST API endpoints:
- wp/v2/font-collections - Endpoints that provide a list of predefined font families, also known as "collections".
- wp/v2/font-families - Provides the endpoints of a parent font family, usually containing one or more fonts (that is, a single font).
- wp/v2/font-families//font-faces - Provides endpoints for individual fonts in a particular font family.
To learn more about each new endpoint, see theREST APIManuals and#57616.
Link to this article:https://www.361sale.com/en/6175The article is copyrighted and must be reproduced with attribution.





















![Emoji[wozuimei]-Photonflux.com | Professional WordPress repair service, worldwide, rapid response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![Emoticon[baoquan] - Photon Wave Network | Professional WordPress Repair Services, Worldwide Coverage, Rapid Response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments