纯代码禁用谷歌字体

收到昨天分享的文章>>>Disable Google Fonts——禁止谷歌字体工具 ,本文采用了一种简单而粗糙的方法来处理谷歌字体无法加载的问题。今天,我无事可做,努力学习这个问题,并从互联网上找到了一些禁止谷歌字体的纯代码。

20220511013024-627b11b0cb9f3.png

WordPress 加载谷歌字体的代码位于 wordpress\\wp-includes\\script-loader.php 文件中,我现在发现的代码主要有三个:

// 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 );
// 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\";
/* * 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 文件中可以。

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\' );

以上。