wordpress后台加载速度慢,Functions.php 用代码加速

wordpress后台加载速度慢,Functions.php 用代码加速

1
2
https://may90.com/building/hm.html
http://www.mlwei.com/1459.html

1. 打开调试模式,查看哪些地方影响速度.

WordPress 后台 – 快捷键F12 – 网络(Network) – F5刷新

1.png
1.png

2. 屏蔽掉无用的后台查询功能,把以下代码添加到你当前主题目录下的函数文件functions.php中:

1
2
cd /home/wwwroot/default/vermaxcn/wp-content/themes/flatsome
vi functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function disable_dashboard_widgets() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');
remove_meta_box('dashboard_primary', 'dashboard', 'core');
remove_meta_box('dashboard_secondary', 'dashboard', 'core');
remove_meta_box('dashboard_right_now', 'dashboard', 'core');
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
remove_meta_box('dashboard_plugins', 'dashboard', 'core');
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');
}
add_action('admin_menu', 'disable_dashboard_widgets');

function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );

wp_deregister_script('autosave');

remove_action('post_updated','wp_save_post_revision' );

add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}return $translations;
}
1
systemctl restart nginx

3. 代码分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//去除后台没必要的功能
function disable_dashboard_widgets() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');//近期评论
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');//近期草稿
remove_meta_box('dashboard_primary', 'dashboard', 'core');//wordpress博客
remove_meta_box('dashboard_secondary', 'dashboard', 'core');//wordpress其它新闻
remove_meta_box('dashboard_right_now', 'dashboard', 'core');//wordpress概况
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');//wordresss链入链接
remove_meta_box('dashboard_plugins', 'dashboard', 'core');//wordpress链入插件
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');//wordpress快速发布
}
add_action('admin_menu', 'disable_dashboard_widgets');
//移除 WordPress 加载的JS和CSS链接中的版本号
function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
//移除自动保存
wp_deregister_script('autosave');
//移除修订版本
remove_action('post_updated','wp_save_post_revision' );
//后台禁用Google Open Sans字体,加速网站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}return $translations;
}

Leave a Reply

Your email address will not be published. Required fields are marked *