Astra_WebFont_Loader::preload_local_fonts()

Get the font files and preload them.


Description


Source

File: inc/lib/webfont/class-astra-webfont-loader.php

	public function preload_local_fonts() {
		// Make sure variables are set.
		// Get the remote URL contents.
		$styles = $this->get_styles();

		// Get an array of locally-hosted files.
		$local_font = array();
		$font_files = $this->get_remote_files_from_css( $styles );

		foreach ( $font_files as $font_family => $files ) {
			if ( is_array( $files ) ) {
				$local_font[] = end( $files );
			}
		}

		// Caching this for further optimization.
		update_site_option( 'astra_local_font_files', $local_font );

		foreach ( $local_font as $key => $local_font ) {
			if ( $local_font ) {
				echo '<link rel="preload" href="' . esc_url( $local_font ) . '" as="font" type="font/' . esc_attr( $this->font_format ) . '" crossorigin>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
			}
		}
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.