How to Log WordPress Errors

 

Have you ever had a WordPress site crash during development or even when live? Often you will see errors of the form:

Notice: Undefined variable: user_id in 
/home/thc0nstantnvescm/public_html/wp-content/themes/mts_schema-child/functions.php 
on line 166

Once you see this error you know something is wrong. However you don't want users to see this error because they are *ugly*. In addition, you want to know if the site is having problems when you are not looking at it.

To log these errors in WordPress, add the following to wp-config.php:

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

These commands will create a log file in /wp-content/debug.log and all the errors will be written there. You can examine this file for useful error messages generated by any user of the site.

Share