Created
July 17, 2020 06:42
-
-
Save shubhw12/f9fdc91c64bc2ee935a2fca4f877a409 to your computer and use it in GitHub Desktop.
Astra and Google fonts preload .
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_action( 'wp_head', 'add_astra_fonts_preload', 1 ); | |
| function add_astra_fonts_preload() { | |
| $font_list = apply_filters( 'astra_render_fonts', Astra_Fonts::get_fonts() ); | |
| $google_fonts = array(); | |
| $font_subset = array(); | |
| $system_fonts = Astra_Font_Families::get_system_fonts(); | |
| foreach ( $font_list as $name => $font ) { | |
| if ( ! empty( $name ) && ! isset( $system_fonts[ $name ] ) ) { | |
| // Add font variants. | |
| $google_fonts[ $name ] = $font['variants']; | |
| // Add Subset. | |
| $subset = apply_filters( 'astra_font_subset', '', $name ); | |
| if ( ! empty( $subset ) ) { | |
| $font_subset[] = $subset; | |
| } | |
| } | |
| } | |
| $google_font_url = Astra_Fonts::google_fonts_url( $google_fonts, $font_subset ); | |
| ?> | |
| <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 /> | |
| <link rel="preload" href="<?php echo $google_font_url;?>" 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;font-display: fallback;}'; | |
| ?> | |
| </style> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment