设置wordpress维护模式
知识点:
由于各种原因导致网站访问出错,此时需开启维护模式,给出一个维护提示的页面,暂停访问,进行维护。
方法一:
根目录建立文件 .maintenance
<?php $upgrading = time();
停止维护,删除此文件即可。
方法二:
1. 在plugins目录中建立维护插件
建立目录 maintenance
建立文件maintenance.php
<?php /** * @package maintenance * @version 1.0 */ /* Plugin Name: maintenance mode Plugin URI: http://www.spkcn.com/ Description: Change to maintenance mode. Author: Spkcn Version: 1.0 Author URI: https://www.spkcn.com/ */ require_once ABSPATH.'wp-includes/pluggable.php'; if(!current_user_can('edit_pages')){ add_filter('stylesheet','switch_maintenance_theme'); add_filter('template','switch_maintenance_theme'); // Remove WPML language selector css in head define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true); } function switch_maintenance_theme($theme='maintenance'){ $theme = 'maintenance'; return $theme; }
2. themes目录中建立维护模板
建立目录maintenance
建立 style.css 文件:
/* Theme Name: Maintenance Theme URI: https://www.spkcn.com Description: maintenance mode Version: 1.0 Author: Spkcn Author URI: https://www.spkcn.com/ Tags: maintenance */
建立 home.php和 index.php:
<!DOCTYPE HTML> <html> <head> <title><?php bloginfo( 'name' ); ?> maintenance</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> <mian role="main"> <div><?php bloginfo( 'name' ); ?> 正在维护中,我们很快就会完成,请耐心等待。</div> </main> </body> </html>
3. 登陆后台激活插件 maintenance mode 进入维护模式,取消激活此插件退出维护模式。
四月 10, 2017 | In: 网页