Created
November 20, 2019 09:33
-
-
Save Swapnildhanrale/8c2c501bc50db8724c9a9f8758a54c53 to your computer and use it in GitHub Desktop.
How to load astra fonts with Preload attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'astra_enable_default_fonts', 'temp_disable_astra_fonts' ); | |
function temp_disable_astra_fonts( $load ) { | |
$load = false; | |
return $load; | |
} | |
add_action( 'wp_head', 'add_astra_fonts_preload', 1 ); | |
function add_astra_fonts_preload() { | |
?> | |
<link rel="preload" href="<?php echo get_site_url(); ?>/wp-content/themes/astra/assets/fonts/astra.woff" as="font" crossorigin /> | |
<link rel="preload" href="<?php echo get_site_url(); ?>/wp-content/themes/astra/assets/fonts/astra.ttf" as="font" crossorigin /> | |
<link rel="preload" href="<?php echo get_site_url(); ?>/wp-content/themes/astra/assets/fonts/astra.svg#astra" as="font" crossorigin /> | |
<style type='text/css'> | |
<?php | |
echo '@font-face {font-family: "Astra";src: url( ' . get_site_url() . '/wp-content/themes/astra/assets/fonts/astra.woff) format("woff"),url( ' . get_site_url() . '/wp-content/themes/astra/assets/fonts/astra.ttf) format("truetype"),url( ' . get_site_url() . '/wp-content/themes/astra/assets/fonts/astra.svg#astra) format("svg");font-weight: normal;font-style: normal;}'; | |
?> | |
</style> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment