wordpress登錄后台如果打開速度慢,一般分為兩部分,第一部分是php虛擬主機的原因,其中主機的原因,又分為很多種情況。第二部分就是WordPress程序本身的問題.這里無憂主機小編主要是講第二部分。所以我們要具體問題具體分析,以下會詳細介紹,什么原因會導致WordPress登錄后台打開速度慢,如何解決。
WordPress登錄后台如果打開速度慢,一般分為兩部分,php主機的原因,其中主機的原因,又分為很多種情況。第二部分就是WordPress程序本身的問題。這里無憂主機小編主要是講第二部分。以下會詳細介紹,什么原因會導致WordPress登錄后台打開速度慢,如何解決。
1、gravatar用戶頭像
拜很多的免費WordPress主題所賜,現在很多朋友使用的WordPress主題,基本都是使用的gravatar頭像,很遺憾的是,目前gravatar基本被牆光了。直接套用一下里面的代碼就可以排除這個問題了。我們直接在當前主題的functions。php文件,在文件中加入以下代碼:
//gravata的頭像轉換為多說的圖片緩存
1
2
3
4
5
|
function
get_avatar_uctheme(
$avatar
) {
$avatar
= preg_replace(
"/http:\/\/(www|\d).gravatar.com/"
,
"http://gravatar.duoshuo.com"
,
$avatar
);
return
$avatar
;
}
add_filter(
'get_avatar'
,
'get_avatar_uctheme'
);
|
2、谷歌字體
同樣是因為被牆而打不開了,同樣很多的主題,默認加載了谷歌字體,我們直接移谷歌字體,就可以排除這個原因了。我們直接在當前主題的functions。php文件。在文件中加入以下代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
//wordpress后台禁用谷歌的字體api
class
Uctheme_Disable_Google_Fonts {
public
function
__construct() {
add_filter(
'gettext_with_context'
,
array
(
$this
,
'disable_open_sans'
), 888, 4 );
}
public
function
disable_open_sans(
$translations
,
$text
,
$context
,
$domain
) {
if
(
'Open Sans font: on or off'
==
$context
&&
'on'
==
$text
) {
$translations
=
'off'
;
}
return
$translations
;
}
}
$disable_google_fonts
=
new
Uctheme_Disable_Google_Fonts;
|
為了保險起見,我們再加入一段代碼,內容如下:
//谷歌字體移除
1
2
3
4
5
6
|
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'
);
|
3、后台插件和主題的更新檢測
這個功能需要謹慎使用,對后台打開速度慢的影響可以說也是相當有限的,當然,正常情況下,我們如果覺得主題不必要再修改,而插件也沒有安裝多少的話,可以使用一下。我們直接在當前主題的functions。php文件,在文件中加入以下代碼:
1
2
3
4
5
6
|
//禁止插件或主題檢查更新,
add_filter(
"pre_http_request"
, disable_plugin_request,10,3);
function
disable_plugin_request(
$a
,
$b
,
$c
){
if
(isset(
$b
[
'body'
][
'plugins'
]) || isset(
$b
[
'body'
][
'themes'
]))
return
array
(
'response'
=>
array
(
'code'
=>404));
return
false; }
|
4、插件數量太多
如果您的worpress上安裝了很多的插件,不妨將其中一些不必要去除,有一些插件,如果是官方發布的還好,如果是一些個人發布的,您都不知道它在后台作了一些什么樣的工作。
5、functions.php函數中插入了些冗余的函數導致加載緩慢