In order to improve website loading speed and protect privacy, many webmasters choose to host their font files locally instead of relying on external services such as Google FontsThis article describes how to download and host fonts locally in GeneratePress theme environment. This article describes the steps to download and locally host font files in GeneratePress theme environment.
![图片[1]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515113746753-image.png)
1. Download the font file
- utilization Google Fonts Helper and other tools to search and select the desired fonts.
![图片[2]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515113909774-image.png)
- Check the necessary font variants to avoid adding to the page load.
![图片[3]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515113921169-image.png)
- Skip the CSS code copying, download the font file zip and unzip it.
![图片[4]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515113939135-image.png)
2. Uploading font files
WordPress The Media Library restricts font file uploads by default.
We recommend using the "Code Snippets" plugin to avoid the risk of directly modifying the theme files.
![图片[5]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515135539650-image.png)
Add a new code snippet to the plugin that pastes open the font file upload permissions for thefunction (math.)Code.
![图片[6]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515135626481-image.png)
After saving and activating the code snippet, themedia libraryUpload all unzipped font files.
![图片[7]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515135643751-image.png)
Add the following PHP Code, temporary open font file upload permission (put in)subtheme functions.php (or managed with a code snippet plugin):
add_filter( 'upload_mimes', function( $mimes ) {
$mimes['woff'] = 'application/x-font-woff';
$mimes['woff2'] = 'font/woff2';
$mimes['ttf'] = 'application/x-font-ttf';
$mimes['svg'] = 'image/svg+xml';
$mimes['eot'] = 'application/vnd.ms-fontobject';
return $mimes.
} );
Upload the unzipped font file, it is recommended to delete the code after uploading.
3. Get a link to the font file
![图片[8]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515135723346-image.png)
- Copy any font file in its entirety URL, e.g.:
http://your-site/wp-content/uploads/2019/02/font-name.woff2 - Remove the filename and keep only the directory path as the CSS Path Usage.
http://your-site/wp-content/uploads/2019/02/
4. Generate and add @font-face CSS
Let's go back to the Google Fonts Helper for downloading font files.
- Fill in the directory path in Google Fonts Helper.
http://your-site/wp-content/uploads/2019/02/
![图片[9]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515140305237-image.png)
- Copy the generated full CSS code.
![图片[10]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515140352212-image.png)
- Paste into WordPress backend "Appearance" → "Customize" → "Attach CSS", or child theme style file.
![图片[11]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515140504286-image.png)
5. Adding Local Fonts to GeneratePress Themes
- Go to "Appearance" → "Customize" → "Typography".
- Adding font names (with CSS)
font-family(Consistent).
![图片[12]-GeneratePress 主题下字体本地托管完整教程:提升加载速度与隐私保护](https://www.361sale.com/wp-content/uploads/2025/05/20250515140629209-image.png)
- Turn off the Google Fonts option and enable local fonts.
- Set the font application range and save to take effect.
6. Make local fonts appear in WordPress block editor.
The block editor does not load customizations by default @font-face CSS.
If CSS is in "Additional CSS", add the code injection editor:
add_filter( 'block_editor_settings_all', function( $editor_settings ) {
$css = wp_get_custom_css_post()->post_content;
$editor_settings['styles'][] = array( 'css' => $css );
return $editor_settings;
} );
If CSS is used in a child theme style.css, add code:
add_filter( 'generate_editor_styles', function( $editor_styles ) {
$editor_styles[] = 'style.css';
return $editor_styles;
} );
Once this is done, the editor will display the local fonts correctly.
summarize
Locally hosted fonts improve loading speed and reduce third-party dependencies. Combined with GeneratePress theme's typography features, complete withcalligraphic styleFile download and upload permissions are turned on,CSS Adding and theme and editor font configurations enables perfect local hosting of fonts, improving the visual and performance performance of your website.
Recent Updates
Link to this article:https://www.361sale.com/en/54546/The article is copyrighted and must be reproduced with attribution.



















![表情[wozuimei]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![表情[baoquan]-光子波动网 | WordPress教程、Elementor教程与故障修复](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments