修改WP引用的google公共库

自己写的三个函数转换和关闭googleapis访问唔到的问题。
 

最近果班扑街借呢样借果样搞到乱七八糟,好了,唔肺话了。

function bd_change_apiscript()
{
	global $wp_scripts;
	foreach ((array)$wp_scripts->registered as $thisscripts)
	{
		if (stristr($thisscripts->src, 'googleapis.com'))
		{
			wp_deregister_script($thisscripts->handle);
			wp_enqueue_script($thisscripts->handle, str_replace( 'googleapis.com', 'lug.ustc.edu.cn', $thisscripts->src ), $thisscripts->deps, $thisscripts->ver, $thisscripts->in_footer );
		}
	}
}
/*
function bd_change_apistyle()
{
	global $wp_styles;
	foreach ((array)$wp_styles->registered as $thisstyle)
	{
		if (stristr($thisstyle->src, 'googleapis.com'))
		{
			wp_deregister_style($thisstyle->handle);
			wp_enqueue_style($thisstyle->handle, str_replace( 'googleapis.com', 'useso.com', $thisstyle->src ), $thisstyle->deps, $thisstyle->ver, $thisstyle->media );
		}
	}
}
*/
function bd_gettext_with_context( $translations, $text, $context, $domain )
{
	if ( $context === 'Open Sans font: on or off' && $text === 'on' )
	{
		$translations = 'off';
	}
	return $translations;
}

add_action('wp_print_scripts', 'bd_change_apiscript');
//add_action('wp_print_styles', 'bd_change_apistyle');
add_action('gettext_with_context', 'bd_gettext_with_context', 9999,4);

前边两个函数是用来分别揾JS同CSS里边的googleapis,最尾个函数是关闭字体的。

直接复制去主题的functions.php里边就用得。


2016.10更新:
由于fonts.googleapis.com已经解释系国内,就唔系搞style果度了。
360的useso.com已经收咗皮了。

本文发布于 。属于 WordPress点滴 分类,被贴了 标签。

《修改WP引用的google公共库》有0个评分

★★★★★
★★★★
★★★
★★
0
0
0
0
0

修改WP引用的google公共库》有2个想法

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注