wordpress优化


wordpress优化

1.  关闭自动更新


// 关闭小版本自动更新
define( 'AUTOMATIC_UPDATER_DISABLED', true );

// 关闭自动更新
remove_action('admin_init', '_maybe_update_core'); // 禁止 WordPress 检查更新
remove_action('admin_init', '_maybe_update_plugins'); // 禁止 WordPress 更新插件
remove_action('admin_init', '_maybe_update_themes'); // 禁止 WordPress 更新主题

add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));
add_filter('pre_site_transient_update_themes', create_function('$a', "return null;"));
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;"));

2.  关闭评论

后台 -> 设置 -> 讨论,不要勾选【允许他人在新文章上发表评论】

3. 修改版本号

修改/wp-includes/version.php中的版本号

4. 使用Ping服务


http://ping.baidu.com/ping/RPC2
http://blogsearch.google.com/ping/RPC2

5. 设置修订版数量


define('WP_POST_REVISIONS', 2);

6. 使用一个标准的Robots.txt文件

7. 移除RSD支持


remove_action('wp_head', 'rsd_link');

8. 移除Windows Live Writer接口


remove_action('wp_head', 'wlwmanifest_link');

9. 移除版本号


remove_action('wp_head', 'wp_generator');

10. 移除谷歌字体


function remove_open_sans() {
	wp_deregister_style( 'open-sans' );
	wp_register_style( 'open-sans', false );
	wp_enqueue_style('open-sans', '');
}
add_action( 'init', 'remove_open_sans' );

11. 移除前后文、第一篇文章、主页meta信息


remove_action( 'wp_head', 'index_rel_link' );
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', 10, 0 );

12. 移除feed


remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );

13. 修改文件上传目录


/* 修改文件上传目录 */
define('UPLOADS', 'uploads');

14. 优化.htaccess


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^.*\.(jpg|png|css|js)(\?ver=.*)?$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

15. 取消相邻文章


remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );


发表回复