feat(typography): migrate from Google Fonts to local font hosting

feat(typography): migrate from Google Fonts to local font hosting

Replaced external Google Fonts integration with locally hosted font files
for Oswald and Roboto.

- Added local @font-face definitions for Oswald (400, 500, 700)
- Added local @font-face definitions for Roboto (400, 500, 700)
- Removed Google Fonts enqueue and external requests
- Implemented unicode-range optimized font loading (latin subset)
- Fixed font file path inconsistencies causing fallback rendering
- Ensured correct font-weight mapping across all variants
- Maintained existing typography system via CSS variables

Result:
- No external font requests (fonts.googleapis.com / fonts.gstatic.com removed)
- Improved performance and privacy (GDPR compliant)
- Consistent rendering with original Google Fonts appearance
- Full control over font loading and optimization
This commit is contained in:
2026-04-23 21:00:32 +02:00
parent d066342413
commit 5152784a20
8 changed files with 128 additions and 32 deletions
+13 -24
View File
@@ -200,19 +200,6 @@ function zeitfresser_enqueue_static_colors() {
);
}
add_action( 'wp_enqueue_scripts', 'zeitfresser_enqueue_static_colors', 20 );
/**
* Load Google Fonts (required for static font setup)
*/
function zeitfresser_enqueue_google_fonts() {
wp_enqueue_style(
'zeitfresser-google-fonts',
'https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;700&family=Roboto:wght@400;500;700&display=swap',
array(),
null
);
}
add_action('wp_enqueue_scripts', 'zeitfresser_enqueue_google_fonts');
function zeitfresser_enqueue_static_fonts() {
wp_enqueue_style(
@@ -281,18 +268,20 @@ function zeitfresser_cleanup_wp_head() {
add_action( 'init', 'zeitfresser_cleanup_wp_head' );
/**
* Ensure Google Fonts domains are allowed and preconnected
* Preload local fonts for better performance
*/
add_filter('wp_resource_hints', function($urls, $relation_type) {
if ($relation_type === 'preconnect') {
$urls[] = 'https://fonts.googleapis.com';
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin' => 'anonymous',
);
}
return $urls;
}, 10, 2);
function zeitfresser_preload_fonts() {
?>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/oswald-400.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/oswald-500.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/oswald-700.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/roboto-400.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/roboto-500.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/fonts/roboto-700.woff2" as="font" type="font/woff2" crossorigin>
<?php
}
add_action('wp_head', 'zeitfresser_preload_fonts', 1);
/**
* Remove front-end dashicons for visitors.