《家庭财务宝典》

wordpress网站速度优化,wp外贸独立站网站速度优化

24次阅读

共计 3871 个字符,预计需要花费 10 分钟才能阅读完成。

wordpress网站速度优化,wp外贸独立站网站速度优化插图

下面给大家讲讲我们多年经验总结出来的优化 WordPress 速度的实战技巧:

  1. 服务器
  2. 模板
  3. 插件
  4. 图片优化
  5. 缓存
  6. 使用 CDN

1、选择一台好的服务器,并进行服务器调优

WordPress 服务器在官网有推荐,Bluehost、DreamHost、SiteGround 都是针对 WordPress 有优化的,环境配置都是一键搭建,没有什么技巧,速度 = 价格。

2、选择一套速度快的模板主题

如果网站没有 seo 的流量,那就是一个工具,只能我们引流过去,所以我们建站的最终目的是流量,不是奢华。seo 做好流量就要速度快,这里我们推荐两款主题:Neve 3.3.0 以下版本、hero2; 再配合 elementor 做单页完全适合中小企业。

3、去掉不必要的插件

插件越多需要执行的程序就越多,除了主题必备插件,这里我们只推荐加装这个插件提升速度:WP Fastest Cache

4、图片优化

网页的大小,其实主要取决于你的图片大小,优化图片有 2 个方向:格式、质量

格式上:选用先进的图片格式,例如 webp

质量上:主要是根据你的实际需要去上传图片或者使用插件优化图片,因为你不可能为了展示一个很小的图就上传一张分辨率几 K 的,完全没必要,浪费空间,也大大降低了加载速度

图片优化方面的插件我们推荐:Converter for Media

5、做好缓存

wordpress 纯动态通过 php 执行程序渲染网页的,原生的 wordpress 从不生成真正的静态 html 页面。就算你用了伪静态使网站 url 看起来是静态 html,但是他本质的运行机制还是全动态的跑 php。wordpress 的插件市场也没有生成纯静态页面的好用的插件,大多数只有缓存插件。基于这样的机制,想优化速度,安装好的缓存插件非常重要。

我们推荐使用:Autoptimize+WP Fastest Cache

专业人士调优,一般都能通过各种技术帮你网站做整体速度优化,正常来说调优完成之后谷歌速度评分基本上 90 分左右了,再差也得有 80 分

6、使用 CDN

这个没什么好说的,就是加速全球节点速度,还有缓存点图片内容

我们推荐使用全球知名 CDN 龙头供应商:Cloudflare

7、10 个 WordPress 必备提高 WordPress 访问速度和精简代码

第一、网站目录反斜杠

//~ 页面链接后添加反斜杠

function itbulu_nice_trailingslashit($string, $type_of_url) {

if ($type_of_url != ‘single’)

$string = trailingslashit($string);

return $string;

}

add_filter(‘user_trailingslashit’, ‘itbulu_nice_trailingslashit’, 10. 2);

添加这个脚本可以使得网站目录后缀 URL 加上反斜杠,默认是没有的。比如:https://www.ttzdm.cn/jzjs/

第二、禁止 emojis

// 禁止 emojis

function disable_emojis() {

remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7);

remove_action(‘admin_print_scripts’, ‘print_emoji_detection_script’);

remove_action(‘wp_print_styles’, ‘print_emoji_styles’);

remove_action(‘admin_print_styles’, ‘print_emoji_styles’);

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_filter(‘tiny_mce_plugins’, ‘disable_emojis_tinymce’);

}

add_action(‘init’, ‘disable_emojis’);

function disable_emojis_tinymce($plugins) {

if (is_array( $plugins) ) {

return array_diff($plugins, array( ‘wpemoji’) );

} else {

return array();

}

}

一般网站用不上 emojis,我们可以禁止。

第三、去掉 CSS/JS 后缀版本号

// 去除加载的 css 和 js 后面的版本号

function sb_remove_script_version($src){

$parts = explode(‘?’, $src);

return $parts[0];

}

add_filter(‘script_loader_src’, ‘sb_remove_script_version’, 15. 1);

add_filter(‘style_loader_src’, ‘sb_remove_script_version’, 15. 1);

第四、禁止自 PING 和版本保存

function no_self_ping(&$links) {

$home = get_option(‘home’);

foreach ($links as $l => $link)

if (0 === strpos( $link, $home) )

unset($links[$l]);

}

add_action(‘pre_ping’, ‘no_self_ping’);

remove_action(‘pre_post_update’, ‘wp_save_post_revision’);

add_action(‘wp_print_scripts’, ‘disable_autosave’);

function disable_autosave() {

wp_deregister_script(‘autosave’);

}

第五、部分头部禁止模块

remove_action(‘wp_head’, ‘wp_generator’);

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’, ‘feed_links_extra’, 3);

remove_action(‘wp_head’, ‘feed_links’, 2);

remove_action(‘wp_head’, ‘rsd_link’);

remove_action(‘wp_head’, ‘wlwmanifest_link’);

remove_action(‘wp_head’, ‘index_rel_link’);

remove_action(‘wp_head’, ‘wp_shortlink_wp_head’, 10. 0);

第六、将 JQ 文件底部加载

// 强制 jquery 库文件底部载入

function ds_print_jquery_in_footer(&$scripts) {

if (! is_admin() )

$scripts->add_data(‘jquery’, ‘group’, 1);

}

add_action(‘wp_default_scripts’, ‘ds_print_jquery_in_footer’);

第七、关闭 XML-RPC

// 关闭 XML-RPC 功能

add_filter(‘xmlrpc_enabled’, ‘__return_false’);

第八、关闭 REST API

// 屏蔽 REST API

add_filter(‘rest_enabled’, ‘__return_false’);

add_filter(‘rest_jsonp_enabled’, ‘__return_false’);

第九、移除头部 JSON

// 移除头部 wp-json 标签和 HTTP header 中的 link

remove_action(‘wp_head’, ‘rest_output_link_wp_head’, 10);

remove_action(‘template_redirect’, ‘rest_output_link_header’, 11);

第十、禁止 Gutenberg 编辑器

// 禁止 Gutenberg 编辑器

add_filter(‘use_block_editor_for_post’, ‘__return_false’);

remove_action(‘wp_enqueue_scripts’, ‘wp_common_block_scripts_and_styles’);

你的工作,由 AI 赋能!🔥

还在为文案、脚本卡壳、做视频、写代码、设计图片灵感枯竭而烦恼吗?🤯

板板 AI,你的工作好帮手!

一键生成    各种文案、脚本、图片、视频、代码、报告,轻松应对各种工作 / 营销需求!

现在注册体验,即可获得:

  • 🎁 30 积分基础模型余额
  • 🎁 3 积分高级模型余额
  • 🎁 3 积分绘画余额

还不快来试试?

点击链接,开启你的 AI 创作之旅!>>>https://www.banbanai.cn

板板 AI,让你的工作效果发挥无限可能! 🚀

正文完
关注板板AI免费获得移动AI助手
post-qrcode
 
天天
版权声明:本站原创文章,由 天天 2024-10-10发表,共计3871字。
转载说明:

本文由 天天资讯网 整理发布,转载请注明出处.
版权声明:部分文章内容或图片来源于网络,我们尊重作者的知识产权。如有侵犯,请联系我们在第一时间删除。

文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月
文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月
文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月
文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月
文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月 文字广告位10/月

温馨提示:请在上面搜索| 查找更多免费资源,如需广告位请联系站长QQ 48704478

《家庭财务宝典》