How to turn on WordPress debug mode
Help centreOn this page
This guide shows how to switch on WordPress debug mode so errors are written to a log file you can read, and how to switch it off again when you’re finished.
Why use debug mode
When something goes wrong, WordPress often shows a vague “critical error” message or a blank page. Debug mode records the actual PHP error, including the file and line number. That usually tells you which plugin or theme is at fault.
The safest way is to send errors to a log file and keep them hidden from visitors. Error messages can reveal file paths and other details you don’t want on public pages.
Edit wp-config.php
- Log in to cPanel. See how to log in to cPanel.
- Open File Manager and go to the folder your site is in, usually
public_html. - Right-click
wp-config.phpand choose Copy to make a backup, for examplewp-config-backup.php. - Right-click
wp-config.phpand choose Edit. - Look for a line containing
WP_DEBUG. It usually readsdefine( 'WP_DEBUG', false );. - Replace that line with these four lines:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
- If there was no
WP_DEBUGline, paste the four lines just above the comment that says “That’s all, stop editing!”. - Click Save Changes.
Make sure each setting appears only once in the file. If WP_DEBUG_LOG or WP_DEBUG_DISPLAY is already defined further down, change those lines rather than adding a second copy, or WordPress will show a warning.
What each line does
WP_DEBUGturns debug mode on.WP_DEBUG_LOGsaves each error into a log file.WP_DEBUG_DISPLAYset tofalsestops errors being printed on your pages.- The
ini_setline tells PHP not to display errors either, as a second safeguard.
Find debug.log
- Load the page that has the problem, or repeat the action that fails, so the error is recorded.
- In File Manager, open
wp-content. - Look for a file called
debug.log. Click Reload if it doesn’t appear straight away. - Right-click it and choose View or Edit to read it.
The newest entries are at the bottom. Each one starts with a date and time, then the type of problem, such as “PHP Fatal error” or “PHP Warning”, then the file path. A path containing wp-content/plugins/plugin-name/ points to that plugin, and one containing wp-content/themes/theme-name/ points to the theme.
Fatal errors are the ones that break a site. Warnings and notices are often harmless and can be ignored while you look for the cause.
If the error points to a plugin and you can’t log in, see how to disable WordPress plugins without logging in.
Turn it off afterwards
Don’t leave debug mode running. The log file grows over time, and anyone who guesses its address may be able to read it.
- Edit
wp-config.phpagain. - Change
WP_DEBUGback tofalse, or remove the four lines and put backdefine( 'WP_DEBUG', false );. - Click Save Changes.
- Delete
wp-content/debug.log, or download it first if you want to keep it for a developer.
Using WP Toolkit instead
Some versions of WP Toolkit include a Debugging option on the site’s card, with switches for the same settings. If you see it, it is a quick way to toggle debug mode without editing files. Check afterwards that the display option is off, so errors are not shown to visitors, and remember to switch it all back off when you’re done. If you can’t find the option, edit wp-config.php as above.
If it doesn’t work
- No debug.log appears. The page may not be producing a PHP error, or WordPress can’t write to
wp-content. Check the folder permissions are 755. The server’s own error log may also show the problem. See how to find error logs in cPanel. - The site broke after editing wp-config.php. A quote or semicolon is probably missing. Restore your backup copy and try again.
- Errors still show on the page. Another plugin or
php.inisetting may be forcing them on. Check you setWP_DEBUG_DISPLAYtofalseand that it isn’t defined twice. - The log mentions running out of memory. See how to increase the WordPress memory limit.
Related guides
Still stuck? Open a support ticket and we’ll help.
WP Toolkit, staging, backups every six hours and free migration of your site.