wordpress页面加载太慢?只需几步就能解决!

wordpress拥有大量用户基础,是博客类型网站的建站首选。但很多时候我们会发现即使服务器已经很给力,网页的加载速度也不是很理想。接下来本文用最简单的方式解决这个问题。

一、去掉多余的css和js

wordpress系统自带了很多css和js文件,这些文件在访问页面的时候会自动加载。大部分主题都会进行一些优化,但其中还有很多是我们用不到的,而且加载很慢,那么我们只要删掉就好了。进入后台,选择外观,编辑。选中functions.php文件。写入以下代码。这里不做具体分析了,都是挑选出来绝大部分情况都用不到的。想知道那一个文件具体是干什么的,搜索一下就好了。

add_filter( ’emoji_svg_url’, ‘__return_false’ );
add_filter( ‘show_admin_bar’, ‘__return_false’ );
remove_action( ‘wp_head’, ‘print_emoji_detection_script’, 7 );
remove_action( ‘wp_head’, ‘wp_resource_hints’, 2 );
remove_action( ‘wp_head’, ‘wp_print_head_scripts’, 9 );
remove_action( ‘wp_head’, ‘wp_generator’ );
remove_action( ‘wp_head’, ‘rsd_link’ );
remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
remove_action( ‘wp_head’, ‘index_rel_link’ );
remove_action( ‘wp_head’, ‘dashicons’, 10, 0 );
remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
remove_action( ‘wp_head’, ‘rel_canonical’ );
remove_action( ‘wp_head’, ‘feed_links’, 2 );
remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
remove_action(‘admin_print_scripts’, ‘print_emoji_detection_script’);
remove_action(‘admin_print_styles’, ‘print_emoji_styles’);
remove_filter(‘the_content’, ‘wptexturize’);
remove_filter(‘comment_text’, ‘wptexturize’);
remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7);
remove_action(‘wp_print_styles’, ‘print_emoji_styles’);
remove_action(’embed_head’, ‘print_emoji_detection_script’);
remove_filter(‘the_content_feed’, ‘wp_staticize_emoji’);
remove_filter(‘comment_text_rss’, ‘wp_staticize_emoji’);
remove_filter(‘wp_mail’, ‘wp_staticize_emoji_for_email’);

add_action( ‘wp_print_styles’, ‘my_deregister_styles’, 100 );
function my_deregister_styles() {
wp_deregister_style( ‘amethyst-dashicons-style’ );
wp_deregister_style( ‘dashicons’ );
wp_deregister_style( ‘font-awesome’ );
wp_deregister_script(‘thickbox’);
wp_deregister_style(‘animate’);
//wp_deregister_style(‘layer’);
}

add_action( ‘wp_enqueue_scripts’, ‘mt_enqueue_scripts’, 1 );
function mt_enqueue_scripts() {
wp_deregister_script(‘jquery’);

}

二、合并压缩所有的css和js文件

安装插件Autoptimize。这是专门整合压缩文件的插件,用的人很多。设置里面可以选择某一类文件是否优化。如html,css,js等,还有一些其他的优化选项,根据需要选择就可以了。

三、压缩图片

如果你的网站图片不是很多,那么完成以上两步,你的网站就已经飞起来了。压缩图片的话,网上搜一下,就会有很多在线压缩站点,同时基本不影响图片质量。最好的办法是每一张图片都事先处理好在使用。当然已经用到的图片,再压缩完成后,重新上传替换,也是一个很大的工程量。这里推荐另一款插件,Enable Media Replace。可以直接替换图片,还可以自动更新所有链接。