Skip to content

Instantly share code, notes, and snippets.

@ivo-ivanov
Created June 6, 2020 15:01
Show Gist options
  • Save ivo-ivanov/f83cd5d0d210badb82df05acbb6e0b60 to your computer and use it in GitHub Desktop.
Save ivo-ivanov/f83cd5d0d210badb82df05acbb6e0b60 to your computer and use it in GitHub Desktop.
Hook to proper load Google Font. (the fastest way 2020) #wordpress
function google_fonts() {
?>
<!-- [1] -->
<link rel="preconnect"
href="https://fonts.gstatic.com"
crossorigin />
<!-- [2] -->
<link rel="preload"
as="style"
href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500&display=swap" />
<!-- [3] -->
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500&display=swap"
media="print" onload="this.media='all'" />
<!-- [4] -->
<noscript>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;500&display=swap" />
</noscript>
<?php
}
add_action('wp_head', 'google_fonts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment