wordpress去除Google字体

网站整体字体设置以及禁用谷歌字体
用wordpress新搭建的网站,是存在Google font的,但在国内,这种字体加载很慢甚至不能加载,严重拖累了网站的打开速度,那么我们就要禁用它,方式就是在functions.php内添加这样一段代码:

//禁用谷歌字体
function mytheme_dequeue_fonts() {
wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
接着就是设置网站的字体,将以下代码添加到style.css中:

/* 整体字体设置 */
body {
font-family:"Segoe UI","Microsoft YaHei","Hiragino Sans GB",STXihei,"Heiti SC",Roboto,"Droid Sans Fallback",Tahoma,Verdana,Arial,"Segoe UI Emoji",sans-serif;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0;
outline:0;
padding:0;
vertical-align:baseline;
}
body.custom-font-enabled {
font-family:"Segoe UI","Microsoft YaHei","Hiragino Sans GB",STXihei,"Heiti SC",Roboto,"Droid Sans Fallback",Tahoma,Verdana,Arial,"Segoe UI Emoji",sans-serif;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0;
outline:0;
padding:0;
vertical-align:baseline;
}
这里有三个注意点。

第一、font-family中的字体名要用英文,比如“微软雅黑”,我们就需要写成“Microsoft YaHei”,这是为了支持更多的浏览器版本和设备;
第二、字体不一定要和我的一样,你也可以根据自己喜欢选择其他字体,比如思源宋体等;第三、除了中文字体,也要有英文字体、特殊字体等,不然可能会出现显示问题。
huan

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: