WordPress托管本地字体

WordPress网站谷歌字体本地化

解决Wordpress中加载font.googleapis.com  gstatic.com访问速度慢 加载异常

WordPress托管本地字体,网站就可以直接调用本服务器字体,中文网站提速也更好。

服务器中wp-content/建立fonts文件夹

确保用的是网络字体格式:TTF、OTF、WOFF或WOFF2

WOFF WOFF2容量更小网页加载更快

使用这个进行转换:

https://transfonter.org/

从谷歌字体下载完之后转换,然后下载(下载文件夹生成stylesheet.css,注意修改里面的 url路径增加实际字体服务器储存路径/wp-content/fonts/),然后上传到最上面路径。

以Poppins字体为例,可以在CSS里面输入下面代码进行调用本地字体。

路径:后台外观-自定义-额外CSS

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Bold.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Bold.woff’) format(‘woff’);
font-weight: bold;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-BlackItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-BlackItalic.woff’) format(‘woff’);
font-weight: 900;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Black.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Black.woff’) format(‘woff’);
font-weight: 900;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-BoldItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-BoldItalic.woff’) format(‘woff’);
font-weight: bold;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Medium.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Medium.woff’) format(‘woff’);
font-weight: 500;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Light.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Light.woff’) format(‘woff’);
font-weight: 300;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Italic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Italic.woff’) format(‘woff’);
font-weight: normal;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-ExtraLightItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-ExtraLightItalic.woff’) format(‘woff’);
font-weight: 200;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-LightItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-LightItalic.woff’) format(‘woff’);
font-weight: 300;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-ExtraBold.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-ExtraBold.woff’) format(‘woff’);
font-weight: bold;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-ExtraLight.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-ExtraLight.woff’) format(‘woff’);
font-weight: 200;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-ExtraBoldItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-ExtraBoldItalic.woff’) format(‘woff’);
font-weight: bold;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-MediumItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-MediumItalic.woff’) format(‘woff’);
font-weight: 500;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-ThinItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-ThinItalic.woff’) format(‘woff’);
font-weight: 100;
font-style: italic;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Regular.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Regular.woff’) format(‘woff’);
font-weight: normal;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-Thin.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-Thin.woff’) format(‘woff’);
font-weight: 100;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-SemiBold.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-SemiBold.woff’) format(‘woff’);
font-weight: 600;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: ‘Poppins’;
src: url(‘/wp-content/fonts/Poppins-SemiBoldItalic.woff2’) format(‘woff2’),
url(‘/wp-content/fonts/Poppins-SemiBoldItalic.woff’) format(‘woff’);
font-weight: 600;
font-style: italic;
font-display: swap;
}

 

0
分享到: