0
0
Wordpressframework~5 mins

Debugging with WP_DEBUG in Wordpress

Choose your learning style9 modes available
Introduction

WP_DEBUG helps you find and fix problems in your WordPress site by showing error messages. It makes your site easier to troubleshoot.

When you want to see PHP errors and warnings on your WordPress site.
When a plugin or theme is not working as expected and you need to find the cause.
When developing a new theme or plugin and you want to catch mistakes early.
When you want to improve your site's code quality by fixing notices and deprecated functions.
Syntax
Wordpress
define('WP_DEBUG', true);
Add this line to your wp-config.php file before the line that says /* That's all, stop editing! */.
Set to false to turn off debugging messages.
Examples
Turns on debugging to show errors and warnings on your site.
Wordpress
define('WP_DEBUG', true);
Turns off debugging messages so visitors don't see errors.
Wordpress
define('WP_DEBUG', false);
Shows errors in a log file instead of on the screen, keeping your site clean for visitors.
Wordpress
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Sample Program

This setup turns on debugging and saves errors to a log file instead of showing them on the website. You can check the file wp-content/debug.log to see what went wrong.

Wordpress
<?php
// wp-config.php snippet
// Enable debugging
define('WP_DEBUG', true);

// Enable debug log to wp-content/debug.log
define('WP_DEBUG_LOG', true);

// Hide errors from displaying on the site
define('WP_DEBUG_DISPLAY', false);

/* That's all, stop editing! Happy blogging. */
OutputSuccess
Important Notes

Always turn off WP_DEBUG on live sites to avoid showing errors to visitors.

Use WP_DEBUG_LOG to keep a record of errors without disturbing users.

Check the debug.log file regularly to catch and fix issues early.

Summary

WP_DEBUG helps you see and fix errors in WordPress.

Turn it on in wp-config.php by setting define('WP_DEBUG', true);.

Use WP_DEBUG_LOG and WP_DEBUG_DISPLAY to control where errors appear.