
wordpress一些優化代碼,實則可用,收藏版
wordpress一些優化代碼,實則可用,收藏版
把下面代碼添加到當前使用主題目錄下的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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//优化代码开始
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_filter('wp_enqueue_scripts', 'remove_wp_open_sans');
// 后台删除Google字体CSS
add_filter('admin_enqueue_scripts', 'remove_wp_open_sans');
add_action( 'init', 'dw_remove_open_sans' );
add_action( 'wp_footer', 'wpjam_page_speed' );
function wpjam_page_speed() {
date_default_timezone_set( get_option( 'timezone_string' ) );
$content = '[ ' . date( 'Y-m-d H:i:s T' ) . ' ] ';
$content .= '页面生成时间 ';
$content .= timer_stop( $display = 0, $precision = 2 );
$content .= ' 查询 ';
$content .= get_num_queries();
$content .= ' 次';
if( ! current_user_can( 'administrator' ) ) $content = "<!-- $content -->";
echo $content;
}
remove_action('wp_head', 'rsd_link'); // 移除RSD标签,即xmlrpc.php
remove_action('wp_head', 'wp_generator'); // 移除版本号
remove_action('wp_head', 'feed_links', 2); // 移除rss feed
remove_action('wp_head', 'feed_links_extra', 3); // 移除额外的rss feed
remove_action('wp_head', 'index_rel_link'); // 移除索引链接
remove_action('wp_head', 'wlwmanifest_link'); // 移除wlwmanifest.xml
remove_action('wp_head', 'start_post_rel_link', 10, 0); // 移除随机文章链接
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // 移除父篇链接
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // 移除下一篇和上一篇链接
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); //移除短链接
function wp_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver='. get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wp_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wp_remove_cssjs_ver', 999 );
remove_action('wp_head', 'wp_resource_hints', 2);
add_filter('rest_enabled', '__return_false'); add_filter('rest_jsonp_enabled', '__return_false');
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
//优化代码结束
💘 相关文章
- 三条命令实现WordPress丝滑顺畅的压缩迁移方案
- 设置WordPress的附件图片地址为二级域名或其它一级域名的方法
- debian安装docker和Docker面板Portainer并部署Wordpress
- wordpress必备的代码神器插件-Code Snippets
- 使用wp-cli来管理WordPress网站
- wordpress压缩前端网页代码
- wordpress A TimThumb error has occured的解决方法
- Openlitespeed wordpress伪静态出现404错误解决方法
- 解决WordPress经典编辑器空白可视化功能不可用的方法
- 一款专注于wordpress开发的本地套件工具-Local