How To Enable Debugging In WordPress

Enable Debugging in WordPress

Table Of Content

Are you seeing a blank screen, error messages, or unexpected behavior on your WordPress site? These issues can be frustrating, especially when they prevent your site from functioning properly. One common example is the “White Screen of Death,” which hides the actual problem behind a completely blank page.

Fortunately, WordPress includes a built-in debugging system that helps you identify and fix such issues. By enabling debugging, you can view detailed error messages and logs that offer insights into what’s going wrong behind the scenes. This guide will walk you through how to use WP_DEBUG mode in WordPress to troubleshoot problems and improve site performance.

Key Takeaways

  • Learn how to enable WP_DEBUG mode in WordPress.
  • Understand what debugging means in WordPress and how it differs from testing.
  • Prevent debug messages from showing on your live site using WP_DEBUG_DISPLAY.
  • Debugging helps both beginners and developers find and fix site issues, improving site performance and user experience.

What is Debugging in WordPress?

Debugging in WordPress is the process of identifying, diagnosing, and fixing issues in your site’s code or configuration. These issues could be related to themes, plugins, or WordPress core files.

To support this process, WordPress provides constants like WP_DEBUG, WP_DEBUG_LOG, and WP_DEBUG_DISPLAY. These make it easier to:

  • Reveal hidden PHP errors, warnings, and notices.
  • Log errors to a file for later review.
  • Identify compatibility issues with themes or plugins.
  • Track down database query problems or script loading issues.

In short, debugging allows you to look under the hood of your website and resolve problems before they negatively affect visitors or performance. It’s especially helpful when a plugin crashes your site, a theme breaks after an update, or something stops working without explanation.

What is the Importance of Debugging in WordPress?

Debugging is an important process for any site because it helps identify bugs and optimize performance. Debugging can be achieved with WP_DEBUG mode. There are many advantages to using WP_DEBUG, here they are:

  • It shows PHP errors, warnings, and notices on your site so you can quickly spot what’s wrong.
  • It’s mainly used by developers during theme or plugin development to make sure everything works properly.
  • By showing small issues (like deprecated functions), it helps you write cleaner and future-proof code.
  • You can use it along with WP_DEBUG_LOG and SCRIPT_DEBUG to log errors or load development versions of CSS/JS files.
  • While great for testing, it’s recommended to turn off WP_DEBUG on a live website to avoid showing errors to visitors.

How to Enable Debugging in WordPress (Step-by-Step)

To enable debugging in WordPress, please follow the process below:

Locating the wp-config.php file

The wp_config file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information. You can access this using FTP or cPanel.

Debugging in WordPress: wp-config.php file
Debugging in WordPress: wp-config.php file

Editing the wp-config.php file

Open the wp_config.php file and then try to locate a specific comment /* That’s all; stop editing! Happy blogging. */ “. Above this, you have to enter a small code to enable debugging in WordPress.

Adding WP_DEBUG code

WP_DEBUG

To enable debug mode, set the WP_DEBUG constant to true. The value of wp_debug is false by default. Write the following code in the config file.

// Enable WP_DEBUG mode
define('WP_DEBUG', true);

Now, check your website, and if any errors are being generated, they will be displayed at the top of your page.

WP_DEBUG_LOG

Write error messages to the log file. If you want to save the errors generated by the WP_DEBUG in a separate file for later analysis, write the code below in the wp-config.php file.

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

A log file named debug.log is generated in the wp-content directory. 

Note: To do anything in WP_DEBUG_LOG, ensure that the WP_DEBUG mode is enabled(true).

Disable debug info from displaying on the frontend

It controls whether to display debug messages inside the HTML of the page or not. To review errors later use WP_DEBUG_DISPLAY in conjunction with the WP_DEBUG_LOG.
Write the following code in the wp_config file to display the error messages.

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Note: For WP_DEBUG_DISPLAY to do anything, WP_DEBUG must be enabled (true).

SCRIPT_DEBUG

SCRIPT_DEBUG will force WordPress to use the “dev” versions of core CSS and JavaScript files rather than the minified versions that are normally loaded.

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

SAVE QUERIES

The SAVEQUERIES saves the database queries to an array and that array can be displayed to help analyze those queries. 

define( 'SAVEQUERIES', true );

The array is stored in the global $wpdb->queries.

NOTE: This will impact your site’s performance, so make sure to turn this off when you aren’t debugging.

Checkout: 8 Useful Tips for WordPress Security

What are the differences between Testing and Debugging?

Here is the difference between Testing and Debugging in WordPress.

AspectTestingDebugging
What it meansChecking the website to see if everything works properlyFixing problems or errors found on the website
PurposeTo find mistakes or issuesTo find out why the issue is happening and fix it
When it’s doneUsually done before launching a new websiteUsually done on a website that is already live
Who does itWeb developers, testers, or website ownersMostly developers or people who know how the website code works
Tools usedBrowser tools, testing plugins, manual checksDebugging plugins, themes, WordPress debug mode, and error logs
ExampleTesting if a contact form works correctlyFixing the form if it doesn’t send emails

Wrap Up

WP_DEBUG displays all PHP notices, warnings, and errors on your site. It also gives you the time it took to retrieve your page’s content, the performance statistics of your website, and the exact line numbers of WordPress’ core files where errors occurred.

FAQs on Debugging in WordPress

What is WP_DEBUG in WordPress?

WP_DEBUG is a built-in WordPress constant used to enable debugging mode. When turned on, it displays PHP errors, warnings, and notices to help identify problems in your website’s code or plugin/theme functionality.

How to enable WordPress Debugging?

Edit the wp-config.php file in your site’s root directory.
Add this line above the file: /* define('WP_DEBUG', true); */

What is the difference between WP_DEBUG and WP_DEBUG_LOG?

WP_DEBUG displays errors on-screen, while WP_DEBUG_LOG logs those errors into a file (debug.log) inside the /wp-content/ folder for review.

Where can I find the WordPress error log?

When WP_DEBUG_LOG is enabled, WordPress saves error messages to wp-content/debug.log.

How do I troubleshoot plugin conflicts in WordPress?

Temporarily disable all plugins and reactivate them one by one while keeping WP_DEBUG enabled. Check the debug log for any errors related to specific plugins.

Leave the first comment

Product Advertisement

Manage your form submission like a pro. Capture form submissions from many popular form building solutions. 

View Details

Related Articles

Check out our latest posts about our plugins and third-party
developers, hostings and new services.

Add Product Videos in WooCommerce

How to Add Product Videos to WooCommerce Galleries(Step-by-Step Guide)

Running an online store can be challenging, especially when it comes to showing your products in a way that helps customers make informed…

Override WooCommerce Templates

A Simple Guide to Override WooCommerce Templates

When running an online store, customizing your store’s appearance often involves customizing WooCommerce templates. Typically, you’d use WooCommerce hooks to make these changes…

Import & Export Products in WooCommerce

How to Import and Export WooCommerce Products

Managing a WooCommerce store can be a complicated task for store owners, especially when dealing with a large number of products. One of…