How to debug WordPress

Debugging the code is one the most important part of any project. You should always TURN ON the debug mode before before you start to develop a WordPress theme or plugin. This will allow you to see warnings, messages and notices generated by WordPress.
By default debugging is disabled in WordPress. To turn ON the debug mode, open your wp-config.php file located in root folder of your WordPress Installation. And look for following line,

define('WP_DEBUG_LOG', true);

Comment or remove the above line and add following lines to wp-config.php file. The following code will log all errors, warnings and notices to a file called debug.log inside the wp-content directory.

// Enable debugging mode
define('WP_DEBUG', true);
// Save all errors to /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// Hide errors and warnings from screen
define('WP_DEBUG_DISPLAY', false);

NOTE: You must paste the above code before /* That's all, stop editing! Happy blogging. */ line.

Also, don’t forget to turn off debug mode before deploying it on production server.

See Also: Automatically Set Post Featured Image in WordPress


Leave a Comment.