网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

在WordPress页面中禁止PHP警告和通知

GG网络技术分享 2025-03-18 16:12 10


问题描述:

When I try to load WordPress, I get a lot of Use of undefined constant ‘view’ - assumed \'‘view’\' type of warnings and notices in the browser. This causes the pages to fill up with these messages before it renders the actual page content expected.

I tried changing error_reporting = E_ALL to error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING but the warnings and notices still show up.

After doing php --ini I located both the 7.0 and 7.1 ini files and updated the value in both and restarted both FPM services on my vagrant.

  • /etc/php/7.0/fpm/php.ini
  • /etc/php/7.1/fpm/php.ini

Why are these still showing up?

网友观点:

You can combine WordPress build-in constants and PHP\'s ini settings.

Place these lines in your wp-config.php

ini_set(\'log_errors\',\'on\');

ini_set(\'display_errors\',\'off\');

ini_set(\'error_reporting\', E_ALL );

define(\'WP_DEBUG\', false);

define(\'WP_DEBUG_LOG\', true);

define(\'WP_DEBUG_DISPLAY\', false);

This way all notices, warnings and errors will not be shown on the front-end of your website, but errors are still accesable by a log file.

###

Looks like you copied the code from some source and pasted in your file, the inverted quote ` is used instead of \', simply change the single quote and it will be fixed.

 change ‘view’ to \'view\' and so on.

标签:

提交需求或反馈

Demand feedback