前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >分享纯代码禁用WordPress谷歌字体

分享纯代码禁用WordPress谷歌字体

作者头像
于飞云计算
修改2019-06-24 17:43:42
1.2K0
修改2019-06-24 17:43:42
举报
文章被收录于专栏:技术经验分享技术经验分享

WordPress加载谷歌字体会拖慢国内程序的运营速度,今天全百科网就给大家分享下如何利用代码禁止谷歌字体的调用方法。

分享纯代码禁用WordPress谷歌字体
分享纯代码禁用WordPress谷歌字体

WordPress 加载谷歌字体的代码位于 wordpress\wp-includes\script-loader.php 文件中,目前我所查到的代码主要有以下三处:

代码语言:javascript
复制
// 全百科网提供代码
// WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
$scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' );
$scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' );
$scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' );
$scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' );
$scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' );
$scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );
代码语言:javascript
复制
// 全百科网提供代码
// Hotlink Open Sans, for now
$open_sans_font_url = "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets";
代码语言:javascript
复制
// 全百科网www.quanbaike.com提供代码
/*
 * Translators: Use this to specify the proper Google Font name and variants
 * to load that is supported by your language. Do not translate.
 * Set to 'off' to disable loading.
 */
$font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' );
if ( 'off' !== $font_family ) {
    $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family );
}

由于代码实在太多了,这里只截取了关键语句,具体大家想看的话可以直接在该文件下搜索查看。然后是禁用代码,直接添加到主题的 functions.php 文件中即可。

代码语言:javascript
复制
// 全百科网提供代码
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' );

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
网站建设
网站建设(Website Design Service,WDS),是帮助您快速搭建企业网站的服务。通过自助模板建站工具及专业设计服务,无需了解代码技术,即可自由拖拽模块,可视化完成网站管理。全功能管理后台操作方便,一次更新,数据多端同步,省时省心。使用网站建设服务,您无需维持技术和设计师团队,即可快速实现网站上线,达到企业数字化转型的目的。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档