| @@ -139,8 +139,10 @@ | ||
| 139 | 139 | private $body_classes = [ |
| 140 | 140 | 'elementor-default', |
| 141 | 141 | ]; |
| 142 | 142 | |
| 143 | + private $google_fonts_index = 0; | |
| 144 | + | |
| 143 | 145 | /** |
| 144 | 146 | * Front End constructor. |
| 145 | 147 | * |
| 146 | 148 | * Initializing Elementor front end. Make sure we are not in admin, not and |
| @@ -227,12 +229,21 @@ | ||
| 227 | 229 | } |
| 228 | 230 | |
| 229 | 231 | // Priority 7 to allow google fonts in header template to load in <head> tag |
| 230 | 232 | add_action( 'wp_head', [ $this, 'print_fonts_links' ], 7 ); |
| 233 | + add_action( 'wp_head', [ $this, 'print_google_fonts_preconnect_tag' ], 8 ); | |
| 231 | 234 | add_action( 'wp_head', [ $this, 'add_theme_color_meta_tag' ] ); |
| 232 | 235 | add_action( 'wp_footer', [ $this, 'wp_footer' ] ); |
| 233 | 236 | } |
| 234 | 237 | |
| 238 | + public function print_google_fonts_preconnect_tag() { | |
| 239 | + if ( 0 >= $this->google_fonts_index ) { | |
| 240 | + return; | |
| 241 | + } | |
| 242 | + | |
| 243 | + echo '<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>'; | |
| 244 | + } | |
| 245 | + | |
| 235 | 246 | /** |
| 236 | 247 | * @since 2.0.12 |
| 237 | 248 | * @access public |
| 238 | 249 | * @param string|array $class |
| @@ -937,10 +948,8 @@ | ||
| 937 | 948 | * @param array $google_fonts Optional. Google fonts to print in the frontend. |
| 938 | 949 | * Default is an empty array. |
| 939 | 950 | */ |
| 940 | 951 | private function enqueue_google_fonts( $google_fonts = [] ) { |
| 941 | - static $google_fonts_index = 0; | |
| 942 | - | |
| 943 | 952 | $print_google_fonts = true; |
| 944 | 953 | |
| 945 | 954 | /** |
| 946 | 955 | * Print frontend google fonts. |
| @@ -958,13 +967,13 @@ | ||
| 958 | 967 | } |
| 959 | 968 | |
| 960 | 969 | // Print used fonts |
| 961 | 970 | if ( ! empty( $google_fonts['google'] ) ) { |
| 962 | - $google_fonts_index++; | |
| 971 | + $this->google_fonts_index++; | |
| 963 | 972 | |
| 964 | 973 | $fonts_url = $this->get_stable_google_fonts_url( $google_fonts['google'] ); |
| 965 | 974 | |
| 966 | - wp_enqueue_style( 'google-fonts-' . $google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 975 | + wp_enqueue_style( 'google-fonts-' . $this->google_fonts_index, $fonts_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 967 | 976 | } |
| 968 | 977 | |
| 969 | 978 | if ( ! empty( $google_fonts['early'] ) ) { |
| 970 | 979 | $early_access_font_urls = $this->get_early_access_google_font_urls( $google_fonts['early'] ); |
| @@ -969,13 +978,13 @@ | ||
| 969 | 978 | if ( ! empty( $google_fonts['early'] ) ) { |
| 970 | 979 | $early_access_font_urls = $this->get_early_access_google_font_urls( $google_fonts['early'] ); |
| 971 | 980 | |
| 972 | 981 | foreach ( $early_access_font_urls as $ea_font_url ) { |
| 973 | - $google_fonts_index++; | |
| 982 | + $this->google_fonts_index++; | |
| 974 | 983 | |
| 975 | 984 | //printf( '<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/earlyaccess/%s.css">', strtolower( str_replace( ' ', '', $current_font ) ) ); |
| 976 | 985 | |
| 977 | - wp_enqueue_style( 'google-earlyaccess-' . $google_fonts_index, $ea_font_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 986 | + wp_enqueue_style( 'google-earlyaccess-' . $this->google_fonts_index, $ea_font_url ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 978 | 987 | } |
| 979 | 988 | } |
| 980 | 989 | |
| 981 | 990 | } |