WordPress网站Web Fonts报404/410错误,已排除插件冲突求解决方法
Hey there, let's work through this web fonts issue you're having with Fetch WordPress—since you've already ruled out plugin conflicts and confirmed the font files exist on your server, we can focus on the most likely culprits here:
- First, paste the full URL of one of your font files (like
https://yourdomain.com/wp-content/themes/your-theme/fonts/your-font.woff2) directly into your browser's address bar. If it fails to download or throws a 403/404 error, the problem is likely file permissions:- Set individual font files to
644and their parent folders to755via FTP or your server control panel (e.g., cPanel). This ensures the server allows public access to the files.
- Set individual font files to
- If the file loads fine directly but GTmetrix still flags an error, move on to checking Fetch WordPress's optimization rules.
Fetch has built-in resource optimization tools that might be rewriting font paths incorrectly:
- Navigate to Fetch's settings panel and look for sections like "Resource Optimization" or "Font Optimization". Temporarily disable features like font preloading or font hosting/optimization, then re-run GTmetrix.
- If the error disappears after disabling these features, add your font file paths to Fetch's exclusion list or optimization whitelist to prevent it from altering those files' loading logic.
Incorrect path references in your theme's CSS or functions.php can cause loading issues, even if the files exist:
- Open your theme's custom CSS or
style.cssfile and check the@font-facerules. Replace relative paths with absolute, full-domain paths to avoid path resolution errors. For example:
Bad (relative path that might be rewritten by Fetch):
Good (absolute path that won't be misinterpreted):@font-face { font-family: 'CustomFont'; src: url('../fonts/custom-font.woff2'); }@font-face { font-family: 'CustomFont'; src: url('https://yourdomain.com/wp-content/themes/your-theme/fonts/custom-font.woff2'); } - If you're enqueuing fonts via
functions.php, double-check that thewp_enqueue_styleorwp_enqueue_scriptcalls use the correct file URLs.
Servers often throw font errors if they don't recognize font file types. Here's how to fix it:
- For Apache servers, add these lines to your root
.htaccessfile:AddType font/woff .woff AddType font/woff2 .woff2 AddType font/ttf .ttf AddType font/eot .eot AddType font/otf .otf - For Nginx servers, add these lines to your server block configuration:
types { font/woff woff; font/woff2 woff2; font/ttf ttf; font/eot eot; font/otf otf; } - Restart your server after making changes, then re-test with GTmetrix.
Fetch WordPress, server-level caches (like Varnish), and CDNs (like Cloudflare) might be storing outdated font loading data:
- Clear Fetch's internal cache via its settings panel.
- Flush your browser cache or use incognito mode to test.
- If you use a CDN or server cache, clear those as well to ensure your latest font configurations are served.
内容的提问来源于stack exchange,提问作者FormaL

