WordPress 实战:移除WordPress后台Google Font API链接

又是一年一度GFW封锁Google的时间段了,童鞋们有没感觉后台略卡了呢?那是因为WordPress使用了Google Font API,解决方法是移除这个字体文件链接或替换为国内公共CDN库链接。

方法一:移除 Google font 链接

function remove_open_sans_from_wp_core() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'remove_open_sans_from_wp_core' );

方法二:替换为360公共库

function dmeng_google_font_cdn_replace($html){
$html = str_replace(array('//ajax.googleapis.com','//fonts.googleapis.com'), array('//ajax.useso.com','//fonts.useso.com'), $html);
return $html;
}

如果你的主题本来就没有载入Google API链接,可以加个判断,添加个 if(is_admin()) 判断是否后台即可。

function dmeng_google_font_ob_cache(){
ob_start('dmeng_google_font_cdn_replace');
}
add_action('wp_loaded', 'dmeng_google_font_ob_cache');

使用方法和总结

把代码添加到主题目录下的functions.php文件最后即可。第二个方法慎用,会把页面中所有的 googleapis.com 替换为 useso.com ,包括文章内容里面的。

原文链接:http://www.dmeng.net/remove-open-sans-from-wp-core.html

你可能感兴趣的:(wordpress)