You ever remember seeing a screen like Error Establishing a Database Connection on your site. This can happen for various reasons, but often users don’t know that their site is down. Also that page itself looks pretty ugly in itself. In this article, we will show you how to customize your database error page in WordPress. We will also show you how to setup a notification for every time your website goes down due to a database error.
您永远记得在您的站点上看到类似“ 建立数据库连接错误”的屏幕。 发生这种情况的原因可能多种多样,但通常用户不知道其站点已关闭。 该页面本身看起来也很丑陋。 在本文中,我们将向您展示如何在WordPress中自定义数据库错误页面。 我们还将向您展示如何在每次由于数据库错误而导致网站关闭时设置通知。
Open a new file and save it as “db-error.php”. Paste the following content inside that. Then upload the file in your /wp-content/ directory.
打开一个新文件,并将其另存为“ db-error.php”。 在其中粘贴以下内容。 然后将文件上传到/ wp-content /目录中。
<?php // custom WordPress database error page
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 600'); // 1 hour = 3600 seconds
// If you wish to email yourself upon an error
// mail("your@email.com", "Database Error", "There is a problem with the database!", "From: Db Error Watching");
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Database Error</title>
<style>
body { padding: 20px; background: red; color: white; font-size: 60px; }
</style>
</head>
<body>
You got problems.
</body>
</html>
Source: CSS Tricks
资料来源: CSS技巧
If you want email notifications, then comment out the mail line. To comment it out, you have to remove // before the mail function. Feel free to customize the landing page however you like. Use these 404 design inspirations as a start.
如果您想要电子邮件通知,请注释掉邮件行。 要注释掉它,您必须在邮件功能之前删除//。 随意自定义登录页面。 使用这些404设计灵感作为开始。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-a-custom-database-error-page-in-wordpress/