首页 > 解决方案 > 自定义字体(不使用@font-face)不会在 HTTPS 协议上加载

问题描述

我正在尝试解决一个问题,即我的自定义字体 (ArcaMojora) 未在 HTTPS 协议上加载,并且我在各处看到了大量使用 @font-face 的代码的修复。在大力搜索我的 WP 主题文件后,我意识到我的主题(Kleanity)根本不使用@font-face,而是在代码下方。

如何调整代码以使自定义字体与 HTTPS 以及 HTTP 一起加载?

任何和所有的帮助表示赞赏!

	// add filter to register custom fonts for font lists 
	add_filter('gdlr_core_custom_uploaded_font', 'kleanity_register_custom_uploaded_font');
	if( !function_exists('kleanity_register_custom_uploaded_font') ){
		function kleanity_register_custom_uploaded_font( $custom_fonts ){

			$custom_font = kleanity_get_option('typography', 'font-upload');
			if( !empty($custom_font) ){
				foreach($custom_font as $font_option){
					$custom_fonts[$font_option['name']] = array(
						'eot' => $font_option['eot'],
						'ttf' => $font_option['ttf'],
					);
				}
			}

			$custom_fonts['ArcaMojora'] = array(
				'name' => 'ArcaMojora',
				'eot' => get_template_directory_uri() . '/fonts/ArcaMajora/ArcaMajora3-Bold.eot',
				'ttf' => get_template_directory_uri() . '/fonts/ArcaMajora/ArcaMajora3-Bold.ttf',
				'font-weight' => 600
			);
			$custom_fonts['ArcaMojora-Heavy'] = array(
				'name' => 'ArcaMojora',
				'eot' => get_template_directory_uri() . '/fonts/ArcaMajora/ArcaMajora3-Heavy.eot',
				'ttf' => get_template_directory_uri() . '/fonts/ArcaMajora/ArcaMajora3-Heavy.ttf',
				'font-weight' => 800,
				'varient' => true
			);
			
			return $custom_fonts;
			
		} // kleanity_register_custom_uploaded_font
	} // function_exists

标签: csswordpressfontscustom-font

解决方案


好吧,最后它一直是@font-face,只是隐藏在我的搜索工具无法访问的文件中。很抱歉,感谢您的帮助!可以在其他地方找到解决方案:Chrome 上 HTTPS 页面上的 Google Web Fonts


推荐阅读