WordPress禁用或去除不必要的功能

  • 酉灿
  • WordPress
  • Sep 11, 2020

wordpress很强大,但是有些功能基本上用不到。本来中国大陆使用wp就非常慢,再用这些没必要的功能或更新简直要把人逼疯。博主搜集了一些优化代码,供大家使用。

一、删除后台不必要的功能

后台有些多余功能是用不到的,可以删除或禁用。将下面代码放在主题的functions.php文件即可。

/*去除后台没必要的功能*/
function disable_dashboard_widgets() { 
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');//近期评论 
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');//近期草稿
remove_meta_box('dashboard_primary', 'dashboard', 'core');//wordpress博客 
remove_meta_box('dashboard_secondary', 'dashboard', 'core');//wordpress其它新闻 
remove_meta_box('dashboard_right_now', 'dashboard', 'core');//wordpress概况 
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');//wordresss链入链接 
remove_meta_box('dashboard_plugins', 'dashboard', 'core');//wordpress链入插件 
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');//wordpress快速发布 
} 
add_action('admin_menu', 'disable_dashboard_widgets');

二、去除、禁用定期更新功能

wordpress会有一些插件、主题的定时检查,还会经常提示更新,强迫症的看了会很烦。将下面代码放在主题的functions.php文件即可。

// 彻底关闭自动更新
add_filter('automatic_updater_disabled', '__return_true');
// 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');
// 移除已有的主题更新定时作业 
wp_clear_scheduled_hook('wp_update_themes');
// 移除已有的自动更新定时作业 
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 移除后台内核更新检查 
remove_action( 'admin_init', '_maybe_update_core' );
// 移除后台插件更新检查 
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
// 移除后台主题更新检查 
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );

// 关闭核心提示
add_filter('pre_site_transient_update_core',create_function('$a', "return null;")); 
// 关闭插件提示
add_filter('pre_site_transient_update_plugins',create_function('$a', "return null;")); 
// 关闭主题提示
add_filter('pre_site_transient_update_themes',create_function('$a', "return null;"));
// 禁止 WordPress 检查更新
remove_action('admin_init', '_maybe_update_core');
// 禁止 WordPress 更新主题
remove_action('admin_init', '_maybe_update_themes'); 
打赏