当你的 WordPress 站点出现数据库错误的时候,默认会看到这样的页面:

你也可以自定义错误页,首先在 「wp-content」 文件夹创建一个 db-error.php 文件,在里边放上这样的代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<?php

/**

    *WordPress 自定义数据库错误页

    *https://www.weixiaoduo.com/database-error-page/

*/

header('HTTP/1.1 503 Service Temporarily Unavailable');

header('Status: 503 Service Temporarily Unavailable');

header('Retry-After: 600');

?>

<!DOCTYPE HTML>

<html>

<head>

    <meta charset="UTF-8">

    <title> 数据库错误</title>

</head>

<body>

    <h1> 数据库错误</h1>

    <p> 自定义数据库错误页</p>

</body>

</html>

这样就可以自定义数据库错误页了。

事实上,这个自定义的错误页实际上是一个 Drop-in 高级插件,了解什么是 Drop-in 高级插件:https://www.weixiaoduo.com/drop-in/