有时可能会用到 WordPress 的站点维护模式,这样既能提醒到访者,又不影响更新维护。需要开启维护模式时,只需添加以下代码到当前主题的 functions.php,完成维护,删除添加的代码,即可退出 WordPress 站点维护模式。

//WordPress 站点维护模式开启
function veatips_wp_maintenance_mode() {
    if(!current_user_can('edit_themes') || !is_user_logged_in()){
        wp_die('<h1 style="color:red">网站更新维护中</h1>');
    }
}
add_action('get_header', 'veatips_wp_maintenance_mode');