如何关闭WordPress中PHP错误

Recently one of our readers asked how to turn off PHP errors in WordPress? PHP warnings and notices help developers debug issues with their code. However it looks extremely unprofessional when they are visible to all your website visitors. In this article, we will show you how to easily turn off PHP errors in WordPress.

最近,我们的一位读者问如何关闭WordPress中PHP错误? PHP警告和注意事项可帮助开发人员调试其代码中的问题。 但是,当您的所有网站访问者都可以看到它们时,它看起来非常不专业。 在本文中,我们将向您展示如何轻松关闭WordPress中PHP错误。

How to turn off PHP errors in WordPress
为什么以及何时应该关闭WordPress中PHP错误? (Why and When You Should Turn Off PHP Errors in WordPress?)

PHP errors that you can see on your WordPress site are usually warnings and notices. These are not like internal server error, syntax errors, or fatal errors, which stop your website from loading.

您可以在WordPress网站上看到PHP错误通常是警告和注意。 这些与内部服务器错误语法错误致命错误不同 ,后者会阻止您的网站加载。

Notices and warnings are the kind of errors that do not stop WordPress from loading your website. See how WordPress actually works behind the scenes for more details.

注意和警告是不会阻止WordPress加载您的网站的一种错误。 有关更多详细信息,请参阅WordPress实际在幕后的工作方式。

PHP errors in WordPress admin area

The purpose of these errors are to help developers debug issues with their code. Plugin and theme developers need this information to check for compatibility and best practices.

这些错误的目的是帮助开发人员调试其代码中的问题。 插件和主题开发人员需要此信息来检查兼容性和最佳实践。

However, if you are not developing a theme, plugin, or a custom website, then these errors should be hidden. Because if they appear on the front-end of your website to all your visitors, it looks extremely unprofessional.

但是,如果您未开发主题,插件或自定义网站 ,则应隐藏这些错误。 因为如果它们出现在您所有访问者的网站前端,则看起来非常不专业。

WordPress warning errors on homepage

If you see an error like above on on your site, then you may want to inform the respective theme or plugin developer. They may release a fix that would make the error go away. Meanwhile, you can also turn these errors off.

如果您在自己的网站上看到类似上面的错误,则可能需要通知相应的主题或插件开发人员。 他们可能会发布使错误消失的修复程序。 同时,您也可以关闭这些错误。

Let’s take a look at how to easily turn off PHP errors, notices, and warnings in WordPress.

让我们看一下如何轻松地关闭WordPress中PHP错误,通知和警告。

关闭WordPress中PHP错误 (Turning off PHP Errors in WordPress)

For this part, you will need to edit the wp-config.php file.

对于这一部分,您将需要编辑wp-config.php文件。

Inside your wp-config.php file, look for the following line:

在您的wp-config.php文件中,查找以下行:


define('WP_DEBUG', true);

It is also possible, that this line is already set to false. In that case, you’ll see the following code:

此行也可能已设置为false。 在这种情况下,您将看到以下代码:


define('WP_DEBUG', false);

In either case, you need to replace this line with the following code:

无论哪种情况,都需要用以下代码替换此行:


ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

Don’t forget to save your changes and upload your wp-config.php file back to the server.

不要忘记保存您的更改并将wp-config.php文件上传回服务器。

You can now visit your website to confirm that the PHP errors, notices, and warnings have disappeared from your website.

现在,您可以访问您的网站以确认PHP错误,通知和警告已从您的网站中消失。

在WordPress中开启PHP错误 (Turning on PHP Errors in WordPress)

If you are working on a website on local server or staging area, then you may want to turn on error reporting. In that case you need to edit your wp-config.php file and replace the code you added earlier with the following code:

如果您正在本地服务器临时区域上的网站上工作,则可能需要打开错误报告。 在这种情况下,您需要编辑wp-config.php文件,并用以下代码替换之前添加的代码:


define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);

This code will allow WordPress to start displaying PHP errors, warnings, and notices again.

此代码将允许WordPress重新开始显示PHP错误,警告和通知。

We hope this article helped you learn how to turn off php errors in WordPress. You may also want to see our list of the most common WordPress errors and how to fix them.

我们希望本文能帮助您学习如何关闭WordPress中的php错误。 您可能还希望查看我们最常见的WordPress错误列表以及如何修复它们。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-turn-off-php-errors-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值