您的位置:首页 > 编程语言 > Go语言

wordpress后台加载ajax.googleapis.com导致打开速度很慢的解决方案

2015-04-17 15:25 706 查看
wordpress后台加载ajax.googleapis.com导致打开速度很慢的解决方案

解决方案:

在主题的functions.php里面添加如下代码:

function hc_cdn_callback($buffer) {
return str_replace('googleapis.com', 'useso.com', $buffer);
}
function hc_buffer_start() {
ob_start("hc_cdn_callback");
}
function izt_buffer_end() {
ob_end_flush();
}
add_action('init', 'hc_buffer_start');
add_action('shutdown', 'hc_buffer_end');


2.

禁用wordpress gravatar使用本地头像提高网页打开速度

修改get_avatar函数,在wp-includes/pluggable.php内。修改后的函数如下:

if ( !function_exists( 'get_avatar' ) ) :
/**
* Retrieve the avatar for a user who provided a user ID or email address.
*
* @since 2.5
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternate text to use in image tag. Defaults to blank
* @return string tag for the user's avatar
*/
function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
if ( ! get_option('show_avatars') )
return false;
if ( false === $alt)
$safe_alt = '';
else
$safe_alt = esc_attr( $alt );
if ( !is_numeric($size) )
$size = '96';
$default = includes_url('images/blank.gif');
$avatar = "";
return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
}
endif;

即使用该函数,仅可能返回一个默认头像(位于wp-includes/images/blank.gif内),再配合simple local avatars或Add Local Avatar插件,就实现了预期的效果。

3.

删除代码:很多人不喜欢用插件那么这个可以修改代码打开/wp-includes/script-loader.php搜索fonts.googleapis.com找到代码位置,直接把//fonts.googleapis.com/…这个链接整个删掉即可

4.依次打开 /wp-includes/script-loader.php,约581行的位置,替换谷歌的字体库为360网站卫士的国内CDN节点(推荐)将上图截图中箭头指示的fonts.googleapis.com换成fonts.useso.com即可。

5.


360网站卫士常用前端公共库CDN服务

http://libs.useso.com/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐