wp_font_dir()
Gets the path and URL of the current fonts folder.
The default folder for uploading fonts is located here: wp-content/uploads/fonts
.
Fonts are used in theme.json
for customizing fonts in the block editor.
A faster alternative to this function: wp_get_font_dir().
There are classes for working with fonts: WP_Font_Library{} and WP_Font_Face{}.
See also: wp_upload_dir().
Uses: wp_upload_dir()
No Hooks.
Returns
Array
. An array of data about the fonts directory:
Array ( [path] => /home/user/www/example.com/wp-content/uploads/fonts [url] => https://example.com/wp-content/uploads/fonts [subdir] => [basedir] => /home/user/www/example.com/wp-content/uploads/fonts [baseurl] => https://example.com/wp-content/uploads/fonts [error] => )
where:
path
- the path to the fonts directory.url
- the URL of the fonts directory.subdir
- not used for fonts.basedir
- the same as path (not used for fonts).baseurl
- the same as url (not used for fonts).error
- in case of an error while retrieving data, the array element error will be equal to true.
Usage
wp_font_dir( $create_dir );
- $create_dir(true|false)
- Should the folder for uploads be checked and created if it does not exist?
Default: true
Examples
#1 Demo
Let's get data about the fonts folder:
$font_dir = wp_font_dir(); print_r( $font_dir ); /* Array ( [path] => /home/user/www/example.com/wp-content/uploads/fonts [url] => https://example.com/wp-content/uploads/fonts [subdir] => [basedir] => /home/user/www/example.com/wp-content/uploads/fonts [baseurl] => https://example.com/wp-content/uploads/fonts [error] => ) */
Changelog
Since 6.5.0 | Introduced. |
wp_font_dir() wp font dir code WP 6.8.1
function wp_font_dir( $create_dir = true ) { /* * Allow extenders to manipulate the font directory consistently. * * Ensures the upload_dir filter is fired both when calling this function * directly and when the upload directory is filtered in the Font Face * REST API endpoint. */ add_filter( 'upload_dir', '_wp_filter_font_directory' ); $font_dir = wp_upload_dir( null, $create_dir, false ); remove_filter( 'upload_dir', '_wp_filter_font_directory' ); return $font_dir; }