Products
GG网络技术分享 2025-03-18 16:13 6
最近,有很多网友都遇到谷歌搜索(香港)google.com.hk打不开,不过直接输入ip:203.208.46.145可以正常访问。谷歌服务不仅影响了我天朝的广大网民,就连我们苦逼的站长(WordPress)也受到了影响,我不会对这个世界再有爱了!
大家都知道WordPress中核心文件中有调用了谷歌的字体库--Google Fonts,若谷歌的此服务不稳定,会导致博客后台字体无法加载,直接影响博客后台打开速度。最苦逼的有些主题(function.php文件)也调用Google Fonts,这将会影响访客打开速度,这实在令人无法忍受。解决方法如下:
方案一:
WordPress新手推荐使用Disable Google Fonts 插件,还有一款国人开发的Remove Open Sans font Link from WP core 插件。不过据说(贴吧)效果不明显,我没用这种方法。
不想用插件,可以在主题functions.php文件里加入以下代码(Remove Open Sans font Link from WP core 插件核心代码):
function coolwp_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', 'coolwp_remove_open_sans_from_wp_core' );
方案二:
360网站卫士推出的一项字体CDN加速服务,具体修改方法如下:
打开wp-includes/script-loader.php文件,搜索关键词“fonts.googleapis.com”,将其替换为“fonts.useso.com”,保存文件,刷新体验效果如何?
方案三:
把下面代码插入主题中的functions.php中:
代码一:
// Remove Open Sans that WP adds from frontend
if (!function_exists('remove_wp_open_sans')) :
function remove_wp_open_sans() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
}
// 前台删除Google字体CSS
//add_action('wp_enqueue_scripts', 'remove_wp_open_sans');
// 后台删除Google字体CSS
add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
endif;
或用代码二:
function remove_open_sans() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'remove_open_sans' );
一些国外主题经常调用谷歌字体,上述方法貌似对前台主题加载谷歌字体无效,墙越来越高了!
WordPress函数post_type_exists检查文章类型是否存在,如果已存在则返回true。通常在使用函数register_post_type()注册文章类型前应该先使用post_type_exists()函数进行检查。
post_type_exists( string $post_type )
$post_type
字符串
文章类型
if ( post_type_exists( \\\'page\\\' ) ) {echo \\\'文章类型page已存在\\\';} else {echo \\\'文章类型page不存在\\\';}
post_type_exists()函数位于:wp-includes/post.php
相关函数:
Demand feedback