WordPress 国内优化 WordPress 图床

tHub - xiebruce/PicUploader: 一个还不错的图床工具,支持Mac/Win/Linux服务器、支持压缩后上传、添加图片或文字水印、多文件同时上传、同时上传到多个云、右击任意文件上传、快捷键上传剪贴板截图、Web版上传、支持作为Mweb/Typora发布图片接口、作为PicGo/ShareX/uPic等的自定义图床,支持在服务器上部署作为图床接口,支持上传任意格式文件。
03:08:36PicGo+GitHub:你的最佳免费图床选择! - 洪卫 - 博客园

图床来了,markdown和wordpress用户的福音,每月一块钱 - 云+社区 - 腾讯云
03:25:38GitHub - gilbitron/WordPress-to-Pico-Exporter: Exports WordPress posts to Markdown files for http://pico.dev7studios.com
03:25:32PicGo GitHub wordpress - Google 搜索
03:15:00使用nginx负载均衡+多个云的免费额度打造免费markdown图床 | | Bruce's Blog

iyaozhen.com/wordpress-china-optimization.html

众说周知 WordPress 是全球使用量第一的开源博客系统,本博客就是基于此搭建的。但是 WordPress 在国内有些水土不服,有些地方没有考虑中国的国情(GFW),需要做一些小优化。以下代码直接添加在主题或者子主题的模板函数 (functions.php)文件中即可,此文件可在后台直接编辑(外观->编辑)。

1. 移除 Google CDN 字体。英文博客使用 web-font 还是很不错,各个平台使用同一种字体,极大地提升了用户体验,但是中文博客基本用不上,而且 Google CDN 被墙,还会极大影响页面加载速度,所以还是直接去掉吧。

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');

2. Gravatar 地址替换。WordPress 默认使用的几个 Gravatar 头像地址都被墙了,建议替换为 V2ex 提供的 CDN 地址(支持 HTTP2)。注意,官方地址路径为 /avatar,V2ex 的 CDN 为 /gravatar。

if (!function_exists('replace_to_v2ex_avatar')) {
    function replace_to_v2ex_avatar($avatarUrl) {
        return preg_replace(["/[0-9]\.gravatar\.com(\/|%2F)avatar/", "/secure.gravatar\.com\/avatar/"], "cdn.v2ex.com/gravatar", $avatarUrl);
    }
}
add_filter('get_avatar', 'replace_to_v2ex_avatar');

3. 使用最新的 jQuery 以及使用 CDN(BootCDN,支持 HTTP2)。需要注意测试,可能有些插件会有兼容问题。

if (!function_exists('register_my_jquery')) {
    function register_my_jquery() {
        if (!is_admin()) {
            wp_deregister_script('jquery-core');
            wp_register_script('jquery-core', '//cdn.bootcss.com/jquery/3.1.1/jquery.min.js', true, '3.1.1');
            wp_enqueue_script('jquery-core');
            
            wp_deregister_script('jquery-migrate');
            wp_register_script('jquery-migrate', '//cdn.bootcss.com/jquery-migrate/3.0.0/jquery-migrate.min.js', true, '3.0.0');
            wp_enqueue_script('jquery-migrate');
        }
    }
}
add_action('wp_enqueue_scripts', 'register_my_jquery');

4. 移除自动 dns-prefetch。WordPress 4.6 增加了 dns-prefetch 功能,他会分析页面注入的 js 等脚本然后,加入 DNS 预加载列表。wp-includes/general-template.php:

当然这个功能出发点是好的,但是有些域名解析很慢,预加载可能会拖慢速度,而且我也不需要使用 emoji 和 Google 字体(默认预加载了这两项)。

remove_action('wp_head', 'wp_resource_hints', 2);