Home

About

« Back to Programming

Use Google Web Fonts on pages loaded over SSL

If you try to use Google Web Fonts by just adding a <link> in your header and if your page is loaded over HTTPS/SSL, you'll most likely get this warning: "The page at https://[youdomain.com] ran insecure content from [...]". The solution is easy, add this bit of code in your <head> tag:

<script type="text/javascript">
  WebFontConfig = {
    google: { families: [ 'Font1', 'Font2' ] }
  };
  (function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
  })();
</script>

Replace "Font1", "Font2" (and add more as needed) with the names of the fonts you want to use.