代码实现禁止WordPress后台加载谷歌字体Google Fonts 提高管理后台速度

原本麦子是准备整理禁止WordPress前端谷歌字体功能的,但是从哪个版本开始的WordPress程序前端已经不再加入谷歌字体,所以前端已经不需要禁止谷歌字体。但是有些时候后台是有谷歌字体的,如果我们发现有谷歌字体导致后台管理登录速度慢,我们可以通过下面的办法来禁止。这里我们依旧采用代码的办法实现。

代码实现禁止WordPress后台加载谷歌字体Google Fonts 提高管理后台速度
//WP禁止后台谷歌字体
add_filter('gettext_with_context', 'disable_open_sans', 888, 4 );
function disable_open_sans( $translations, $text, $context, $domain )
{
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}

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

我们在添加之前先看看是否有加载谷歌字体,如果没有的话也无需使用这个代码。

5/5 - (1 vote)
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享