手动开启WordPress站点维护模式

发布时间:

在更新程序或插件中,WordPress前端会显示处于维护模式,如果想临时启用维护模式,让用户知道你的站点在维护中,可以通过下面的代码实现。

手动开启WordPress站点维护模式

手动开启WordPress站点维护模式

将下面代码添加到当前主题函数模板functions.php中:

function zm_maintenancemode() {
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
wp_die('网站正在维护请稍候!');
exit;
}
}
add_action('get_header', 'zm_maintenancemode');

添加代码后,前端会显示维护中,但不影响登录后台操作。

出处:http://www.thecreativedev.com/how-to-put-wordpress-site-into-maintenance-mode/