Enable Error Reporting in WordPress
When things aren’t working as expected on your site, or you get an error notification from WordPress, you will need to check the error logs for your site.
WordPress runs on PHP and the error logs let you know when PHP had problems running code. PHP errors are often the reason plugins or your theme aren’t working as expected.
Table of Contents
Enable WordPress’ built-in error reporting
PHP itself can report errors and logging can be set at the server level, but WordPress also has its own way to report errors.
To enable WordPress’ own error log reporting you must edit your wp-config.php
file. You can do this via FTP or the file manager of your hosting control panel.
- Open your wp-config.php file in a text editor
- First do a search for any existing, related commands by searching for
wp_debug
. If you find any you can either set the same values as below, or just remove them. - Add the following lines:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);- Save the file and upload back to the server.
I’ll explain what each of the 3 lines does.
The first line which sets WP _DEBUG to true
enables error logging.
The second displays the log in a file, debug.log
The third prevents the errors being displayed on the front end of your site. In this case, they will only be logged to the file. This is desirable so that your users don’t need to see any errors if it’s not necessary, and to make sure that information about your site isn’t displayed to the public. This can be considered a security risk.
A debug.log file will be generated in the wp-content
folder whenever errors occur on the site.
To prevent unnecessary logging, you should turn off error logging when you have resolved the issue you are investigating. To do that you can do either of the following:
- Remove the lines you added
- Comment them out by adding
//
before each line, like this://define('WP_DEBUG', true);
The advantage of doing this is that the next time you need to troubleshoot you don’t have to hunt for the info again, just remove the//
before each line, and you will reactivate the logging.
Add the debugging lines anywhere after the opening <?php
tag and the following line near the bottom of the file:
/* That's all, stop editing! Happy blogging. */
Change the location of the log file
If you prefer to save the log to a different location, you can do so by adding the following line:
define( 'WP_DEBUG_LOG', '/tmp/wp-errors.log' );
Replace /tmp/wp-errors.log
with the path and desired name of your file.
WordPress Error Log Not Working
If the above steps don’t work, there is something specific to your installation going wrong. Try the following:
- Check server permissions:
- WordPress must be able to write to the
wp-content
folder. Try manually creating an empty debug.log file and then see if anything is written to it. - Contact your host if you are not sure about writing permissions.
- It could be file/folder permissions, or owner permissions – again you can ask your host about this.
- WordPress must be able to write to the
- If you are on a local setup, your MAMP/WAMP/XAMPP configuration could be setting different error log rules.
- Check
wp-config
to make sure the log hasn’t been set to display in a different location. - Create a
phpinfo
file to see where the logs are being output to.
Alternate sources of error reporting
Your host
Your host typically also keeps track of PHP errors. Often you can find the log file via FTP, or in your cPanel.
FTP
Start by looking in the root folder of your WordPress installation. Often you will find a file named error_log
.
Depending on your host and its setup, you may find the error logs within a folder named /logs/ in the root of your site.
Just ask your host if you can’t find the file.
cPanel
If your host uses cPanel, look for the Errors section in the Metrics panel:
How to see WordPress error reports on managed hosts
If you are using a managed WordPress host, they probably give you easy access to this.
WP Engine
In the WP Engine panel of your WordPress dashboard, you’ll find quick access to the error logs:
Kinsta
Log in to your MyKinsta dashboard, click on Sites, then Error Logs.
Flywheel
You can export your log files from your Flywheel account dashboard.
Siteground
Go to the Websites section → Site Tools → Statistics → Error Log
Query Monitor plugin
The Query Monitor plugin is very helpful and logging errors is one of the many things it can do. If you prefer not to edit your wp-config file, this plugin could be an alternative. It displays some information int he admin toolbar of your site and if there are errors, it will change color. Clicking on it opens a panel in your browser to show further info.
However, if your site isn’t accessible at all due to a fatal PHP error, you won’t be able to use it.
How to turn off PHP error reporting in WordPress
To turn off WordPress’ error reporting, check your wp-config.php
file.
Make sure that wp_debug
is set to false, or comment it out with a double slash at the beginning of the line:
define('WP_DEBUG', false);
or
// define('WP_DEBUG', true);
wp_debug_log
should be to set to false or commented out:
define('WP_DEBUG_LOG', false);
or
//define('WP_DEBUG_LOG', true);
wp_debug_display
should be set to false or commented out:
define('WP_DEBUG_DISPLAY', false);
or
//define('WP_DEBUG_DISPLAY', true);
Also check if you have the following definition:
@ini_set( ‘log_errors’, true );
If so, either comment it out or set it to false
.
If you find the following line, change the 1
to 0
or comment out the line:
@ini_set('display_errors', 1);
Code language: CSS (css)
For more guidance on troubleshooting problems on your WordPress site, please see our in-depth guide.