3

WordPress如何用代码实现网站关闭状态 WP将网站维护模式插件分享

 2 years ago
source link: https://www.huhexian.com/5301.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WordPress如何用代码实现网站关闭状态 WP将网站维护模式插件分享

青山 2021-10-1814:12:36评论948字

平常我们使用WordPress站点网站的时候,难免有需要临时关闭网站或者暂时的闭站,暂停处理的话,我们没有就需要取消解析或者是删除网站文件达到关闭网站的效果。那么有什么方法可以让我们不关站实现访客访问网站关闭状态呢,正常如果有有管理员或者注册用户的是可以正常访问的。在这里给大家整理到2个办法可以实现这种要求。

WordPress如何用代码实现网站关闭状态 WP将网站维护模式插件分享

1、无插件方法

  1. function lxtx_wp_maintenance_mode(){
  2. if(!current_user_can('edit_themes') || !is_user_logged_in()){
  3. $logo = 'https://www.itbulu.com'; // 请将此图片地址换为自己站点的 logo 图片地址
  4. $blogname = get_bloginfo('name');
  5. $blogdescription = get_bloginfo('description');
  6. wp_die('<div style="text-align:center"><img src="'.$logo.'" alt="'.$blogname.'" /><br /><br />'.$blogname.'正在例行维护中,请稍候...</div>', '站点维护中 - '.$blogname.' - '.$blogdescription ,array('response' => '503'));
  7. }
  8. }
  9. add_action('get_header', 'lxtx_wp_maintenance_mode');

我们需要更换上面代码的LOGO地址,然后将代码添加到 Functions.php 文件中。这样只要是游客就访问设置的闭站内容。如果是有有访问的用户是可以正常访问的。

2、插件方法

这里,有体验过使用 "Coming Soon Page, Maintenance Mode & Landing Pages"这款插件。这款软件虽然是有付费功能,但是基本的免费用户是够用的。

WordPress如何用代码实现网站关闭状态 WP将网站维护模式插件分享

这款插件功能很强大,但是我们只要用到基本功能即可。

WordPress如何用代码实现网站关闭状态 WP将网站维护模式插件分享

这里我们开启ACTIVE然后设置。

设置开启且设置缓存清理后,我们如果用非管理员和非用户登录状态访问,是可以看到COME SOON 的界面的,这个默认登录界面是可以设置的。

这样,我们就可以开启WordPress站点闭站维护功能,有需要可以选择使用。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK