0

I tried to upload fonts in WordPress in wp-includes/fonts. Then I go in Apperance -> Editor -> Style.css and here I have something like this

@font-face {
    font-family: helvetica_light;
    src: url(/wp-includes/fonts/helvetica_light.otf);
}

Looking in console I saw this error..I want to know why and what can I do to remove the error.

2 Answers 2

1

You should never touch any files in wp-includes or wp-admin. Why? Because the next time you update WordPress, any changes you made will get erased.

Option 1 - Easy

If you want to use Google fonts with your WordPress theme, try a plugin like Easy Google Fonts or WP Google Fonts.

Option 2 - More Work

If you want to programmatically add Google fonts without using a plugin, you'd paste this code in your themes' functions.php file.

Note: there is no Helvetica Light font available from Google. Open Sans seems to be a close match though.

function my_custom_google_fonts() {
  wp_enqueue_style( 'my-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:300,400', false ); 
}
add_action( 'wp_enqueue_scripts', 'my_custom_google_fonts' );

Then you need to reference that new font in your themes' style.css file.

body {
  font-family: 'Open Sans', sans-serif;
}
4
  • I modifed the location of the fonts..I moved in fonts folder of the template. But the error still remains..Where I can modify ..bacause the font works just I want to remove the error. I don't want to upload fonts with Google Fonts
    – Aste1959
    Commented Sep 27, 2016 at 8:13
  • Not sure why you insist on downloading the fonts. Google recommends embedding them. They load faster and you don't need to worry about updates. developers.google.com/fonts/…
    – cowgill
    Commented Sep 28, 2016 at 1:27
  • can't find the fonts I want on google fonts
    – Aste1959
    Commented Sep 28, 2016 at 7:09
  • @Aste1959 in that case, try this plugin. You can upload the font you're trying to use. wordpress.org/plugins/use-any-font
    – cowgill
    Commented Sep 28, 2016 at 8:30
0

If the font is installed on your computer, your browser will show it on your site, regardless of whether the font has been loaded. So I'd start with checking the site on a different device and see if the font shows up there. If not, check the path to the font. Url's in stylesheets are relative to the location of the sheet, not of the site root. That should enable you to make sure the font is really loaded on all devices.

Now to the error. Apparently there is code in your site that tries to load any font mentioned in your css file from Google. The error is thrown because Google doesn't know this font. The ver4.6.1 at the end of the url is the current WordPress version, which is most likely generated by a call to wp_enqueue_style or wp_register_style. That call is wrong anyway, because Google doesn't like the version part and would throw an error even if the font did exist (the $ver parameter should be null).

Without further knowledge it's impossible to say where this code is. I'd start with checking the theme's functions.php, but it may also be some font related plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.